I have website on port 8080 and I want to force https on it. ex. If I type http://mywebsite.com:8080, it should redirect to https://mywebsite.com:8080
How can I do this in nginx conf?
I have website on port 8080 and I want to force https on it. ex. If I type http://mywebsite.com:8080, it should redirect to https://mywebsite.com:8080
How can I do this in nginx conf?
Nginx will emit non-standard error code 497
which could be processed with error_page
directive. So this would work:
server {
listen 8080 ssl;
error_page 497 @force_https;
location @force_https {
return 301 'https://$host:$server_port$request_uri';
}
}
Works:
$ curl -I http://localhost:8080/test/me
HTTP/1.1 301 Moved Permanently
...
Location: https://localhost:8080/test/me