Nginx session丟失問題處理解決方法
在用nginx的反向代理tomcat的路徑中,可能會出現(xiàn)session丟失問題。每發(fā)送一次請求 JESSIONID 都會發(fā)生改變,說明上一次形成的session丟失,從而創(chuàng)建新的session。
第一種情況:
server{ listen 80; server_name www.jiahemdata.com www.jiahemdata.cn; charset utf-8; location /{ proxy_redirect off; proxy_pass http://127.0.0.1:8093; proxy_set_header Host $host; proxy_set_header Referer $http_referer; proxy_set_header X-Real-Ip $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } access_log logs/tomcat_access.log; }
由于當前對的nginx只是監(jiān)聽一個端口,不設(shè)定路徑,所有一般不會出現(xiàn)session丟失的問題。
第二種情況:
server{ listen 80; server_name www.jiahemdata.com www.jiahemdata.cn; root /opt/tomcat-jhyx/webapps/jhyx/; charset utf-8; location /{ proxy_pass http://127.0.0.1:8093/jhyx/; proxy_set_header Host $host; proxy_set_header Referer $http_referer; proxy_set_header X-Real-Ip $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } access_log logs/tomcat_access.log; }
這種情況,指定了tomcat的文件夾,不僅僅是一個端口監(jiān)聽,會導致每次請求都會發(fā)生變化,導致session丟失。
第三種情況:
server{ listen 80; server_name www.jiahemdata.com www.jiahemdata.cn; root /opt/tomcat-jhyx/webapps/jhyx/; charset utf-8; location /{ proxy_redirect off; proxy_pass http://127.0.0.1:8093/jhyx/; proxy_cookie_path /jhyx/ /; //設(shè)置cookie路徑,從而不導致每次發(fā)生請求發(fā)生變化。 proxy_cookie_path /jhyx /; proxy_set_header Host $host; proxy_set_header Referer $http_referer; proxy_set_header X-Real-Ip $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } access_log logs/tomcat_access.log; }
這時候,發(fā)現(xiàn)你的問題依然沒有解決,這時候你在想,我明明已經(jīng)設(shè)置cookie路徑了,怎么還不行呢,那是因為你請求的時候沒有發(fā)送cookie。
第四種情況:
server{ listen 80; server_name www.jiahemdata.com www.jiahemdata.cn; root /opt/tomcat-jhyx/webapps/jhyx/; charset utf-8; location /{ proxy_redirect off; proxy_pass http://127.0.0.1:8093/jhyx/; proxy_cookie_path /jhyx/ /; proxy_cookie_path /jhyx /; proxy_set_header Host $host; proxy_set_header Referer $http_referer; proxy_set_header Cookie $http_cookie; //請求發(fā)送時攜帶cookie信息 proxy_set_header X-Real-Ip $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } access_log logs/tomcat_access.log; }
希望你在茫茫網(wǎng)絡(luò),找到一個正確的解決方法。
到此這篇關(guān)于Nginx session丟失問題處理解決方法的文章就介紹到這了,更多相關(guān)Nginx session丟失內(nèi)容請搜索本站以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持本站!
版權(quán)聲明:本站文章來源標注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學習參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。