我正在尝试重写请求http://www.example.com:88到https://www.example.com:4430
目前,我被非标准端口困住了。这是我的配置:
upstream pool {
server 127.0.0.1:5001;
server 127.0.0.1:5002;
}
server {
listen 88;
listen 4430 default ssl;
if ($ssl_protocol = "") {
rewrite ^ https://$server_name:4430/$uri permanent;
# this also fails with https://www.example.com/:4430
#rewrite ^/(.*)$ https://$host:4430/$1 permanent;
#rewrite ^ https://www.example.com:4430/ permanent;
}
location / {
proxy_pass http://pool;
proxy_set_header Host $host;
proxy_redirect off;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
这导致http://www.example.com:88/path被重写为https://www.example.com/path:4430
获取域名后的端口的语法是什么?
答案1
我建议server
对 http 重定向使用单独的重定向,对 ssl 使用另一个重定向:
server {
listen 88;
return 302 https://$host:4430$request_uri;
}
server {
listen 4430 ssl default_server;
...