3¡¢Redis°²×°
3-1¡¢Redis for windowsÏÂÔØ
Èç¹û»áÅäÖÃRedisµÄͬѧ£¬ÇëÂÔ¹ý´ËÕ½ڣ¬Ö±½Ó½øÈëNginx¡£
RedisÏÂÔØ£ºhttps://github.com/MSOpenTech/redis
£¡´Ë´¦Îª¿Ó£¬Çë×¢Ò⣡
ÐÞ¸ÄRedis.windows.conf£¬Èç¹û²»Ð޸ģ¬Ô¶³Ì²»ÄÜ·ÃÎÊRedis
1¡¢½«bind 127.0.0.1 ¸Ä³ÉÁËbind 0.0.0.0¡£×¢Ò⣺½øÈëÉú²ú»·¾³Ê±ºò£¬ÒªÆôÓÃÃÜÂ룬·ñÔò»áÊÇRedis©¶´£¬¾ßÌåÇë×ÔÐжÈÄïºÍ×Ô¼º¹«Ë¾µÄÔËά°¢Å£
2¡¢protected-mode yes ¸Ä³É protected-mode no
ÏêϸÐ޸ĵĴ«ËÍÃÅ£º redis¿ªÆôÔ¶³Ì·ÃÎÊ
3-2¡¢Æô¶¯Redis
redis-server redis.windows.conf
ÉÏͼΪredisÆô¶¯³É¹¦£¬Ä¬ÈÏ6379£¬¿ÉÒÔͨ¹ýredis-cli½øÐвâÊÔ£¬¿´±ðµÄ»ú×ÓÄÜ·ñ·ÃÎÊ¡£»¹¿ÉÒÔÔÚÕÒ¸öredis¿ÉÊÓ»¯¹¤¾ß¿´¿´ÀïÃæ´æÁËɶ£¬Ò²¿ÉÒÔ¼à¿ØSessionÊÇ·ñ³Ö¾Ã»¯µ½RedisÖÐÁË¡£3-3¡¢ÑéÖ¤SessionÊÇ·ñ³Ö¾Ã»¯µ½Redis
ÔËÐÐRedisSessionProviderÕâ¸öÏîÄ¿¡£Í¬Ò»¸öIISÏ£¬Í¬ÓòÃû£¬²»Í¬IP£¬Í¬Ò»ä¯ÀÀÆ÷£¬²»Í¬¶Ë¿ÚÒ»¸öÊÇ2459£¬Ò»¸öÊÇ2490¡£
¡¾×¢Òâ¡¿
²»Í¬ä¯ÀÀÆ÷SessionIdÊDz»Í¬µÄ¡£±ØÐë±£Ö¤SessionId£¬²âÊÔ±ØÐëÊÇͬһ¸öä¯ÀÀÆ÷½ø³Ì·Ö³öµÄ²»Í¬×Ó±êÇ©²Å¿ÉÒÔ£¬ÕâÑùSessionIdÊǹ²ÏíµÄ¡£
¸Ð¾õ³É¹¦ÁË£¬ÈÃÎÒÃÇ¿´¿´ÕâÑùµÄÍØÆËͼ£º
‡å¡¡ÕâÊÇɶÍæÒ⣿Îҵķֲ¼Ê½ÄØ£¿Õâ¸öÍØÆËͼºÜÏÔÈ»²»ÊÇ·Ö²¼Ê½°¡£¬»¹Á½¸öIP£¬ÎÒ»¹ÒªÔÚÇ°Ãæ×ö¸ö·ÓɵǼҳÃ棿ÕâʱNginx¸ÃµÇ³¡ÁË¡£
Èý¡¢Ngnix
1¡¢Ngnix°²×°&ÏÂÔØ
ÏÂÔصØÖ·£º
2¡¢nginx.confÅäÖÃÐÞ¸Ä
2-1¡¢¡¾½Ó¿ÚÐ޸ġ¿
listen 80; ¸Ä³É listen 1100; ÒòΪһ°ã¶¼±»80¶¼±»Ê¹Óá£
2-2¡¢¡¾Ôö¼Ó¸ºÔؾùºâ¡¿
upstream Jq_one { server 127.0.0.1:8770; server 192.168.8.138:7777; } server { ..... }
2-3¡¢¡¾location½ÚµãÐ޸ġ¿
location / { root html; index index.aspx index.html index.htm; #ÆäÖÐjq_one ¶ÔÓ¦×ÅupstreamÉèÖõļ¯ÈºÃû³Æ proxy_pass Jq_one; #ÉèÖÃÖ÷»úÍ·ºÍ¿Í»§¶ËÕæʵµØÖ·£¬ÒÔ±ã·þÎñÆ÷»ñÈ¡¿Í»§¶ËÕæʵIP proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }
2-4¡¢¡¾NginxÆô¶¯ÃüÁî¡¿
C:\server\nginx-1.0.2>start nginx
»ò
C:\server\nginx-1.0.2>nginx.exe
2-5¡¢¡¾NginxÖØÐÂÔØÈëÃüÁî¡¿
C:\server\nginx-1.0.2>nginx.exe -s reload
2-6¡¢¡¾²Î¿¼ÎÄÕ¡¿
ÏêϸÅäÖô«ËÍÃÅ:nginx+iisʵÏÖ¸ºÔؾùºâ
ËÄ¡¢Session·Ö²¼Ê½¹²Ïí
1¡¢ÍØÆËͼ
ͨ¹ýNginx+RedisʵÏÖ¶ÔSessionµÄ·Ö²¼Ê½¹²Ïí¹¦ÄÜ¡£Í¨¹ý²âÊÔ£¬·¢ÏÖSession·Ö²¼Ê½¹²Ïí¹²ÓÐÁ½ÖÖ½â¾ö·½°¸¡£
2¡¢ÀûÓÃNginxµÄIp_Hash½øÐÐSession·Ö²¼Ê½¹²Ïí
ʹÓÃnginx½«Í¬Ò»ipµÄÇëÇó·ÖÅäµ½¹Ì¶¨·þÎñÆ÷£¬ÐÞ¸ÄÈçÏ¡£ip_hash»á¼ÆËãip¶ÔÓ¦hashÖµ£¬È»ºó·ÖÅäµ½¹Ì¶¨·þÎñÆ÷
upstream Jq_one{
server 127.0.0.1:8770;
server 192.168.8.138:7777;
¡¡ ip_hash;
}
Ч¹û¿ÉÒÔÀí½âΪ¾ÍÊÇÒ»¸öIp£¬Í¨¹ýNginx·Óɵ½IIS_1ÉÏÃ棬ÔÚ¶à´ÎÇëÇ󣬻áÒ»Ö±ÔÚIIS_1ÉÏ£¬²»»á·Óɵ½IIS_2ÉÏÃæ¡£
3¡¢ÀûÓÃMachineKey½øÐÐSession·Ö²¼Ê½¹²Ïí
Ip_HashÔÚÒ»¶¨³Ì¶ÈÉϽâ¾öÁËSession·Ö²¼Ê½¹²ÏíµÄÎÊÌ⣬µ«ÊÇ×ܸоõûÓз¢»Ó³önginx¾ùºâ¸ºÔصŦÄÜ£¬¼ÌÐø¸ÄÔì
3-1¡¢ÏÖ½«Ip_HashÈ¥µô
È¥µôIp_HashÖØÆôNginx£¬´ò¿ªÍøÕ¾£¬µã»÷ÉèÖÃSession°´Å¥£¬½á¹û±¨´í
3-2¡¢web.configÌí¼ÓMachineKey
¡¡