解决 nginx 反向代理时 session 丢失 无效的问题
配置增加 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 /; } }
参考资料 nginx.org/en/docs/http/ngx_http_proxy_module.html
Q群讨论 236201801