在用nginx的反向代理tomcat的路徑中,可能會(huì)出現(xiàn)session丟失問題。每發(fā)送一次請(qǐng)求 JESSIONID 都會(huì)發(fā)生改變,說明上一次形成的session丟失,從而創(chuàng)建新的session。

第一種情況:
1234567891011121314server{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;}由于當(dāng)前對(duì)的nginx只是監(jiān)聽一個(gè)端口,不設(shè)定路徑,所有一般不會(huì)出現(xiàn)session丟失的問題。
第二種情況:
1234567891011121314server{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的文件夾,不僅僅是一個(gè)端口監(jiān)聽,會(huì)導(dǎo)致每次請(qǐng)求都會(huì)發(fā)生變化,導(dǎo)致session丟失。
第三種情況:
1234567891011121314151617server{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路徑,從而不導(dǎo)致每次發(fā)生請(qǐng)求發(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;}這時(shí)候,發(fā)現(xiàn)你的問題依然沒有解決,這時(shí)候你在想,我明明已經(jīng)設(shè)置cookie路徑了,怎么還不行呢,那是因?yàn)槟阏?qǐng)求的時(shí)候沒有發(fā)送cookie。
第四種情況:
123456789101112131415161718server{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; //請(qǐng)求發(fā)送時(shí)攜帶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ò),找到一個(gè)正確的解決方法。
網(wǎng)站題目:Nginxsession丟失問題處理解決方法
本文來源:http://chinadenli.net/article46/cjegeg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機(jī)、企業(yè)網(wǎng)站制作、電子商務(wù)、軟件開發(fā)、服務(wù)器托管、網(wǎng)站排名
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)