I am trying to force ssl redirect, but my domain has a port like so domain.com:8888
The following doesn't seem to be working, now I am not even able to access the site if I add the rewrite
server {
listen 8888;
server_name sy-system.net;
rewrite ^ https://$server_name:8888$request_uri? permanent;
ssl on;
ssl_certificate /path/to/certs/domain.pem;
ssl_certificate_key /path/to/certs/domain.key;
}
It isn't possible to handle both SSL and non-SSL requests on a single port. You'll need to use a second port for the SSL version if you want to serve both on the same domain.
There are two ways to do this, through a dual HTTP HTTPS server block or using two server blocks (preferred) This uses one server block to listen to the 8888 port and the standard 443 SSL port.
There is another way that avoids if statements by splitting the server into two blocks.
Please note that these were not tested since I use standard ports (80,443) but inferred from reading the documentation. You might also want to include the IP Address in the listen statement since SSL must be bound to a dedicated IP anyways.
Sources:
It is possible.
If you you are using the port in the URI:
For no port in URI: