我将nginx设置为反向代理,以访问在其他主机上运行的服务并添加SSL加密。我正在使用以下配置:
server {
listen 9000 ssl;
server_name my.domain.de;
ssl_certificate "/etc/pki/nginx/server.crt";
ssl_certificate_key "/etc/pki/nginx/private/server.key";
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location /service/ {
proxy_pass http://remote_host:8999/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
}
}
当我尝试打开URL https://my.domain.de:9000/service/
时,响应为302重定向,其中Location标头设置为https://remote_host:8999/ui
,但应为https://my.domain.de:9000/service/ui
。
当我通过将行listen 9000 ssl;
更改为listen 9000;
来停用ssl时,它可以正常工作。
我已经尝试显式指定proxy_redirect http://remote_host:8999/ https://my.domain.de:9000/service/;
,无论如何,这都是默认的行为,但这并没有帮助。
顺便说一句:直接访问https://my.domain.de:9000/service/ui
也可以。唯一的问题是nginx无法正确替换来自远程主机的302响应中的Location标头。
不仅重定向不起作用很烦人,而且我也不喜欢代理服务器的主机名以这种方式公开。