0

I am using Ubuntu and Nginx.

I have my site hosted under SSL protection.

If I type in the domain name in a browser without the 's' in 'https' in will redirect to 'https'. But if I type in the IP address of the domain name it will not redirect to 'https'. It iwll just show in the address bar 'http://xxx.xxx.xxx.xxx

I thought this:

server { listen 80 default_server; listen [::]:80 default_server; server_name _; return 301 https://$host$request_uri; } 

would solve this buy it does not.

Yours Novice...

1 Answer 1

0

Try creating another server section with the IP address as server_name- You better make the server name also explicit for your domain name (instead of _). Then redirect from the new server section (IP-Address) to the domain name (same thing you did with port 80).

For example:

server { server_name 12.34.56.178; listen 80; listen 443 ssl; listen [::]:80; listen [::]:443 ssl; return 301 https://example.com; } 

...and do not forget to restart nginx with systemctl restart nginx

Have you tried it like that and restarted your browser to test it? It is sometimes hard to debug stuff when there is a browser cache. Therefore I prefer to use wget -O- http://12.34.56.78 or curl -o- http://12.34.56.78 for testing.

1
  • Hi, did not work I am afraid. The ipaddress still shows in the address bar and it still does not redirect to https Commented Dec 3, 2020 at 8:30

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.