How to redirect ip to https domain in nginx?

Member

by aubrey , in category: Third Party Scripts , 2 months ago

How to redirect ip to https domain in nginx?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by jasen_gottlieb , 2 months ago

@aubrey 

To redirect IP requests to the HTTPS domain in Nginx, you can add a server block in your Nginx configuration file with the following configuration:

1
2
3
4
5
6
7
server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name _;

    return 301 https://yourdomain.com$request_uri;
}


Replace yourdomain.com with your actual domain name.


After adding this configuration, don't forget to reload Nginx for the changes to take effect. You can do this by running:

1
sudo systemctl reload nginx