Nginx 没有保留来自重定向后端 tomcat 服务器的 url。
Nginx 网址://develop-application.example.com/
后端 tomcat url://application.example.com/
tomcat 重定向 url://application.example.com/application
我希望客户端浏览器 URL 始终保持https://develop-application.example.com/不管 tomcat 返回什么。
配置:
server {
listen 443 proxy_protocol;
set_real_ip_from 0.0.0.0/0;
real_ip_header proxy_protocol;
access_log /var/log/nginx/develop-application.example.com.https.access.log elb_log;
server_name develop-application.example.com;
ssl on;
ssl_certificate /etc/nginx/ssl/example.com.crt.chained;
ssl_certificate_key /etc/nginx/ssl/example.com.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
location / {
proxy_pass https://application-ssl/;
proxy_redirect default;
# proxy_set_header Host $http_host;
proxy_set_header Host $host;
proxy_ssl_session_reuse off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
}
}
upstream application-ssl {
server application.example.com:443 weight=100;
least_conn;
}
答案1
proxy_redirect default
在使用标签时不起作用upstream
。您需要明确规定规则,例如:
proxy_redirect https://application.example.com/ https://develop-application.example.com/;
看这个文件了解完整语法。