高级nginx HTTP到HTTPS重定向自定义和不同的端口



我有一个以下nginx配置文件,我想将所有http重定向到https,但具有不同的server_name和自定义端口

server {
listen 80;
server_name *.abc.example.com abc.example.com abc.example.local:123;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name *.abc.example.com abc.example.com abc.example.local:456;
}

这有点不同,因为其他server_name的非自定义端口==>http上的abc.example.local:123需要重定向到https上的abc.example.local:456

处理这种特殊情况的最好方法是什么,以便它正确地将所有http重定向到https,而不考虑server_name,如果它有http和https的不同端口或没有

server_name不能有端口,只有listen可以指定端口。

如果你想让abc.example.local监听端口123 -你将需要一个单独的服务器块。然后另一个服务器块将监听端口456。

最新更新