佳木斯湛栽影视文化发展公司

主頁 > 知識(shí)庫 > Nginx session丟失問題處理解決方法

Nginx session丟失問題處理解決方法

熱門標(biāo)簽:硅谷的囚徒呼叫中心 網(wǎng)站建設(shè) 阿里云 使用U盤裝系統(tǒng) 百度競(jìng)價(jià)點(diǎn)擊價(jià)格的計(jì)算公式 智能手機(jī) 美圖手機(jī) 檢查注冊(cè)表項(xiàng)

在用nginx的反向代理tomcat的路徑中,可能會(huì)出現(xiàn)session丟失問題。每發(fā)送一次請(qǐng)求 JESSIONID  都會(huì)發(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;
  }

由于當(dāng)前對(duì)的nginx只是監(jiān)聽一個(gè)端口,不設(shè)定路徑,所有一般不會(huì)出現(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的文件夾,不僅僅是一個(gè)端口監(jiān)聽,會(huì)導(dǎo)致每次請(qǐng)求都會(huì)發(fā)生變化,導(dǎo)致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路徑,從而不導(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。

 第四種情況:

 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;  //請(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è)正確的解決方法。

到此這篇關(guān)于Nginx session丟失問題處理解決方法的文章就介紹到這了,更多相關(guān)Nginx session丟失內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

標(biāo)簽:煙臺(tái) 黃山 賀州 懷化 湖北 通遼 山南 湘潭

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Nginx session丟失問題處理解決方法》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    个旧市| 车险| 通州市| 德昌县| 巴中市| 福泉市| 锦屏县| 平塘县| 自治县| 綦江县| 黄梅县| 萍乡市| 大田县| 江都市| 皋兰县| 鄱阳县| 阿城市| 绥宁县| 西藏| 永清县| 登封市| 横山县| 万安县| 金寨县| 安庆市| 宜阳县| 荣昌县| 义马市| 灵璧县| 格尔木市| 灯塔市| 临夏县| 斗六市| 潼关县| 万源市| 应城市| 宁武县| 新营市| 辽宁省| 新化县| 蒲城县|