解决 nginx 反向代理时 session 丢失 无效的问题
原文 blog.csdn.net/joyous/article/details/79966593
因为原始路径和代理路径发生了变化,导致 session 丢失,服务端获取的 session 无效,需要修改 nginx 配置做适当修改,参考更具体信息请看 http://nginx.org/en/docs/http/ngx_http_proxy_module.html 有详细描述。
配置增加 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 /;
}
}