I have a the following nginx configuration file where i want to redirect all http to https but with different server_name
and custom ports
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;
}
this is a bit different because of the non-custom ports for the other server_name
===> abc.example.local:123
on http that need to redirect to abc.example.local:456
on https
What will be best way to approach this special case so that it properly redirects all http to https regardless of server_name and if it has different ports for http and https or not
server_name
can't have a port - only listen
can specify a port.
If you want abc.example.local
to listen on port 123 - you will need a separate server block for it. And then another server block which will listen on port 456.