事情的經過時這樣的~~,我看了好多好多百度中nginx負載均衡中解決session問題的方式,我選擇了研究url_hash的方式。經過一番配置之后,我越發覺得這百度搜出來的帖子也太過久遠了吧,去http://wiki.nginx.org/上找了找這個模塊
,在github下載的位置上看到了這樣一段話:
NOTE: This module is obsolete as of Nginx 1.7.2, which includes the hashdirective. This repository remains for historical interest only. 我的理解是此版本是絕對的使用nginx1,7,2,此庫僅為歷史感興趣的參考,而百度翻譯則是此模塊為過時的,我就無法理解了。
正在迷茫之際,我看到了tengine,這是淘寶對nginx的一種擴展的優化吧。然后我就轉而研究這個了,發現在tengine之中有一個叫做ngx_http_upstream_session_sticky_module的模塊,很是貼合我的目的,他是利用用戶的cookie來保持對session的支持。具體原理還有待研究,總之得試試吧
安裝過程可以參考這個:http://www.mamicode.com/info-detail-98992.html。(指出這個文章有問題的地方,在安裝nginx的時候使用 ./configure –PRefix=/opt/nginx –user=www –group=www –with-http_stub_status_module –with-http_ssl_module –with-http_gzip_static_module –with-openssl=/usr/local/src/openssl-1.0.1h –with-zlib=/usr/local/src/zlib-1.2.8 –with-pcre=/usr/local/src/pcre-8.35 –with-jemalloc=/usr/local/jemalloc-3.6.0這個命令)
經過各種踩坑之后,整好了:(這個界面也是尊重nginx,依然那么簡約 。 - - ?。?
那么我們就來試試那個神奇的模塊吧,配置如下:
upstream rock{ server 127.0.0.1:8081; server 127.0.0.1:8082; session_sticky;}server { server_name www.rockcoding.com rockcoding.com; listen 80; index index.html index.htm index.jsp; location / { proxy_pass http://rock; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #access_log /data/log/rockman/www.rockcoding.com main; #日志文件 }}公司的同事,對于外網來說ip都一樣,只要訪問到不同的兩臺服務器且連續刷新不會改變session不會失效(其實就是不會跳轉到另一臺服務器),那么就成功了。兩臺電腦訪問,或者不同的瀏覽器訪問都可以,模塊式基于cookie來判斷的~
嗯,比ip_hash強多了,但是要編譯那么多東西,總覺得還需要再深入研究一下,才方便使用這個tengine吧~
|
新聞熱點
疑難解答