0

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.

user3448600
  • 1,449
  • 2
  • 12
  • 12

1 Answers1

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
  • 7,636
  • 3
  • 25
  • 55