HTML5¼¼Êõ

Session·Ö²¼Ê½¹²Ïí = Session + Redis + Nginx - °ÁÒí·Éº®(2)

×ÖºÅ+ ×÷ÕߣºH5Ö®¼Ò À´Ô´£ºH5Ö®¼Ò 2017-03-10 16:00 ÎÒÒªÆÀÂÛ( )

3¡¢Redis°²×° 3-1¡¢Redis for windowsÏÂÔØ Èç¹û»áÅäÖÃRedisµÄͬѧ£¬ÇëÂÔ¹ý´ËÕ½ڣ¬Ö±½Ó½øÈëNginx¡£ RedisÏÂÔØ£ºhttps://github.com/MSOpenTech/redis £¡´Ë´¦Îª¿Ó£¬Çë×¢Ò⣡ ÐÞ¸ÄRedis.windows.conf£¬Èç¹û²»Ð޸ģ¬Ô¶

image

image

 

3¡¢Redis°²×°

3-1¡¢Redis for windowsÏÂÔØ

     Èç¹û»áÅäÖÃRedisµÄͬѧ£¬ÇëÂÔ¹ý´ËÕ½ڣ¬Ö±½Ó½øÈëNginx¡£

     RedisÏÂÔØ£ºhttps://github.com/MSOpenTech/redis

image

£¡´Ë´¦Îª¿Ó£¬Çë×¢Ò⣡

     ÐÞ¸Ä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

image

     ÉÏͼΪredisÆô¶¯³É¹¦£¬Ä¬ÈÏ6379£¬¿ÉÒÔͨ¹ýredis-cli½øÐвâÊÔ£¬¿´±ðµÄ»ú×ÓÄÜ·ñ·ÃÎÊ¡£»¹¿ÉÒÔÔÚÕÒ¸öredis¿ÉÊÓ»¯¹¤¾ß¿´¿´ÀïÃæ´æÁËɶ£¬Ò²¿ÉÒÔ¼à¿ØSessionÊÇ·ñ³Ö¾Ã»¯µ½RedisÖÐÁË¡£

3-3¡¢ÑéÖ¤SessionÊÇ·ñ³Ö¾Ã»¯µ½Redis

     ÔËÐÐRedisSessionProviderÕâ¸öÏîÄ¿¡£Í¬Ò»¸öIISÏ£¬Í¬ÓòÃû£¬²»Í¬IP£¬Í¬Ò»ä¯ÀÀÆ÷£¬²»Í¬¶Ë¿ÚÒ»¸öÊÇ2459£¬Ò»¸öÊÇ2490¡£

    

1[6]

¡¾×¢Òâ¡¿

     ²»Í¬ä¯ÀÀÆ÷SessionIdÊDz»Í¬µÄ¡£±ØÐë±£Ö¤SessionId£¬²âÊÔ±ØÐëÊÇͬһ¸öä¯ÀÀÆ÷½ø³Ì·Ö³öµÄ²»Í¬×Ó±êÇ©²Å¿ÉÒÔ£¬ÕâÑùSessionIdÊǹ²ÏíµÄ¡£

image

     ¸Ð¾õ³É¹¦ÁË£¬ÈÃÎÒÃÇ¿´¿´ÕâÑùµÄÍØÆËͼ£º

image

     ‡å¡­¡­ÕâÊÇɶÍæÒ⣿Îҵķֲ¼Ê½ÄØ£¿Õâ¸öÍØÆËͼºÜÏÔÈ»²»ÊÇ·Ö²¼Ê½°¡£¬»¹Á½¸öIP£¬ÎÒ»¹ÒªÔÚÇ°Ãæ×ö¸ö·ÓɵǼҳÃ棿ÕâʱNginx¸ÃµÇ³¡ÁË¡£

 

Èý¡¢Ngnix 

1¡¢Ngnix°²×°&ÏÂÔØ

      ÏÂÔصØÖ·£º

2¡¢nginx.confÅäÖÃÐÞ¸Ä

image

2-1¡¢¡¾½Ó¿ÚÐ޸ġ¿

       listen   80; ¸Ä³É  listen   1100; ÒòΪһ°ã¶¼±»80¶¼±»Ê¹Óá£

image

2-2¡¢¡¾Ôö¼Ó¸ºÔؾùºâ¡¿

upstream Jq_one { server 127.0.0.1:8770; server 192.168.8.138:7777; } server { ..... }

 

image

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¡¢ÍØÆËͼ

image

         ͨ¹ý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ÉÏÃæ¡£

2

 

 

3¡¢ÀûÓÃMachineKey½øÐÐSession·Ö²¼Ê½¹²Ïí

     Ip_HashÔÚÒ»¶¨³Ì¶ÈÉϽâ¾öÁËSession·Ö²¼Ê½¹²ÏíµÄÎÊÌ⣬µ«ÊÇ×ܸоõûÓз¢»Ó³önginx¾ùºâ¸ºÔصŦÄÜ£¬¼ÌÐø¸ÄÔì

3-1¡¢ÏÖ½«Ip_HashÈ¥µô

    È¥µôIp_HashÖØÆôNginx£¬´ò¿ªÍøÕ¾£¬µã»÷ÉèÖÃSession°´Å¥£¬½á¹û±¨´í

image

3-2¡¢web.configÌí¼ÓMachineKey

¡¡

1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

Ïà¹ØÎÄÕÂ
  • ¡¾G¡¿¿ªÔ´µÄ·Ö²¼Ê½²¿Êð½â¾ö·½°¸£¨Ò»£© - ¿ªÆª - Ñ°ÕÒºÍг

    ¡¾G¡¿¿ªÔ´µÄ·Ö²¼Ê½²¿Êð½â¾ö·½°¸£¨Ò»£© - ¿ªÆª - Ñ°ÕÒºÍг

    2017-01-24 14:01

  • ASP.Net MVC4+Memcached+CodeFirstʵÏÖ·Ö²¼Ê½»º´æ - ±¼ÅÜ°É£¡Ð¡¹ù

    ASP.Net MVC4+Memcached+CodeFirstʵÏÖ·Ö²¼Ê½»º´æ - ±¼ÅÜ°É£¡Ð¡¹ù

    2017-01-01 13:00

  • sessionStorage ºÍ localStorage ¡¢cookie - goumingming

    sessionStorage ºÍ localStorage ¡¢cookie - goumingming

    2016-12-29 12:01

  • WEBÇ°¶Ë¹¤³Ìʦ(ʵ¼ù)ÖÆ×÷ÌìÆøÔ¤±¨ÄѶÈ:¼òµ¥ - SessionOne

    WEBÇ°¶Ë¹¤³Ìʦ(ʵ¼ù)ÖÆ×÷ÌìÆøÔ¤±¨ÄѶÈ:¼òµ¥ - SessionOne

    2016-10-16 14:00

ÍøÓѵãÆÀ
®