How to redirect every vhost to https but without duplicating configuration. I have 4 websites on the same vps running Nginx and I want to redirect everything to https.
Asked
Active
Viewed 1,340 times
1 Answers
2
Like this...
Redirect ALL requests to https In catch-all server examples the strange name “_” can be seen
server {
listen 80;
listen [::]:80;
server_name _;
access_log /var/log/nginx/www-301_access.log;
error_log /var/log/nginx/www-301_error.log;
location / {
return 301 https://$host$request_uri;
}
}
Redirect specific domain names
server {
listen 80;
listen [::]:80;
server_name example.com *.example.com example.org *.example.org;
access_log /var/log/nginx/www-301_access.log;
error_log /var/log/nginx/www-301_error.log;
location / {
return 301 https://$host$request_uri;
}
}
Jacob Evans
- 8,431