Tested in Ubuntu 14 / Nginx 1.11
If you use a custom port to serve SSL and you want to force a secure connection redirecting from http to https, a solution is use error_page directive with code 497:
server { listen 8080 ssl; root /usr/share/nginx/mydomain; index index.html index.php; ssl_certificate /etc/ssl/certs/mydomain.com.crt; ssl_certificate_key /etc/ssl/private/mydomain.com.key; error_page 497 https://$host:$server_port$request_uri; ... }
Don’t forget to reload nginx:
~ $ /etc/init.d/nginx reload