频道栏目
首页 > 资讯 > Linux > 正文

如何解决nginx反向代理时session丢失无效的问题?

18-04-17        来源:[db:作者]  
收藏   我要投稿

解决 nginx 反向代理时 session 丢失 无效的问题

因为原始路径和代理路径发生了变化,导致 session 丢失,服务端获取的 session 无效,需要修改 nginx 配置做适当修改。

配置增加proxy_pass http://127.0.0.1:8080/speedacc/; 可以轻松实现代理,但如果路径代理路径和原始路径发生改变,就必须告诉服务器,cookie_path 有所转换 需要添加proxy_cookie_path /speedacc /;

也就是将原始服务器的http://127.0.0.1:8080/speedacc/ 代理到 https://speedacc.localhost1,配置如下,若不需要 ssl 的话,端口通畅都是 80,而不是443

https 代理配置

    # HTTPS server
    
    server {
        listen       443 ssl;
        server_name  localhost;
        server_name  speedacc.localhost1;
               
        ssl_certificate      ssl/server.crt;
        ssl_certificate_key  ssl/server.key;

        #ssl_session_cache    shared:SSL:1m;
        #ssl_session_timeout  5m;

        #ssl_ciphers  HIGH:!aNULL:!MD5;
        #ssl_prefer_server_ciphers  on;
        
        #参考资料
        #http://nginx.org/en/docs/http/ngx_http_proxy_module.html
        location / {
            root   html;
            index  index.html index.htm;
            
            proxy_pass http://127.0.0.1:8080/speedacc/;
            proxy_cookie_path  /speedacc /;            
        }
    }

不带安全连接的 http 代理设置

    # HTTP server
    
    server {
        listen       80 ssl;
        server_name  localhost;
        server_name  speedacc.localhost1;
               
        #ssl_certificate      ssl/server.crt;
        #ssl_certificate_key  ssl/server.key;

        #ssl_session_cache    shared:SSL:1m;
        #ssl_session_timeout  5m;

        #ssl_ciphers  HIGH:!aNULL:!MD5;
        #ssl_prefer_server_ciphers  on;
        
        #参考资料
        #http://nginx.org/en/docs/http/ngx_http_proxy_module.html
        location / {
            root   html;
            index  index.html index.htm;
            
            proxy_pass http://127.0.0.1:8080/speedacc/;
            proxy_cookie_path  /speedacc /;            
        }
    }
相关TAG标签
上一篇:如何从用户的Windows ISO镜像文件中查找Windows版本?
下一篇:Linux系统下的数据监控工具使用介绍
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站