Nginx上开启https, 后端使用Tomcat, 两者间走http协议, 但发现如果tomcat应用存在跳转时, 则客户端浏览器会出现400 Bad Request的错误, 通过抓包发现原因是302跳转响应的Location头中的URL是http协议的, 在tomcat的端号采用非标准80端口时会导致客户端出现400. 解决方案是修改nginx.conf, 让nginx将302跳转响应能智能的修改location头域的内容, 即添加以下一行到配置中的server段
proxy_redirect http:// $scheme://;
例如:
server
{
listen 8443;
server_name test.com;
access_log logs/test.com.access.log main;
ssl on;
ssl_certificate /home/test/cer/server.crt;
ssl_certificate_key /home/test/cer/server.key;
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location /projectname
{
proxy_pass http://192.168.1.33:8080;
proxy_set_header Host $host:$server_port;
proxy_redirect http:// $scheme://;
}
...}
proxy_redirect http:// $scheme://;
例如:
server
{
listen 8443;
server_name test.com;
access_log logs/test.com.access.log main;
ssl on;
ssl_certificate /home/test/cer/server.crt;
ssl_certificate_key /home/test/cer/server.key;
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location /projectname
{
proxy_pass http://192.168.1.33:8080;
proxy_set_header Host $host:$server_port;
proxy_redirect http:// $scheme://;
}
...}