Talktomegoose
Talktomegoose

Reputation: 123

Nginx - https://www not 301 redirecting

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

Upvotes: 0

Views: 347

Answers (2)

Rahul Sharma
Rahul Sharma

Reputation: 5995

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;
}

Upvotes: 1

Youssef CH
Youssef CH

Reputation: 741

server {

    listen 80 default_server;


    server_name _;


    return 301 https://$host$request_uri;

}

Upvotes: 0

Related Questions