How to redirect http traffic to https in nginx
## Redirect *all* port 80 requests
server {
listen 80 default_server;
server_name _;
return 301 https://$host$request_uri;
}
## redirect only specific apps
server {
listen 80 default_server;
server_name _;
return 301 https://$host$request_uri;
}
## Other servers can then be https-only
server {
listen 80;
server_name foo.com;
return 301 https://foo.com$request_uri;
}
server {
listen 443 ssl;
server_name bar.com;
}
References:
- https://serversforhackers.com/c/redirect-http-to-https-nginx