Home > database >  Nginx - https://www not 301 redirecting
Nginx - https://www not 301 redirecting

Time:09-06

I am moving to a new domain and have set up 301 redirects on my ec2 instance.

Currently I have the following:

server {
   listen 80;
   server_name olddomain.co.uk;
   return 301 $scheme://www.newdomain.com$request_uri;
}

this works fine for www.olddomain.co.uk and olddomain.co.uk. However it does not work for https://www.olddomain.co.uk

I am wondering how I can make it so the redirect also works with https://www...

Thanks

CodePudding user response:

Your server isn't listening to https:// i.e. 443 port. Connection to https://www.olddomain.co.uk would simply be refused. Add proper ssl configurations to your nginx file and it should be fine.

server {
   listen 80;
   listen 443 ssl;
   server_name olddomain.co.uk;
   return 301 $scheme://www.newdomain.com$request_uri;
}

CodePudding user response:

server {

    listen 80 default_server;


    server_name _;


    return 301 https://$host$request_uri;

}
  • Related