Question

How To Redirect Old IP To New IP UBUNTU NGINX

Hello, I need help for Redirect Old IP to New IP in UBUNTU NGINX ? can you please help explain how to do it step by step Thanks…


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi @LittleTurquoiseShip,

For redirect old IP to a new hostname:

server {
    listen 80;
    server_name 111.111.111.111; 
    return 301 $https://www.new_host.com$request_uri; 
}

If you want to redirect to another ip:

server {
    listen 80;
    server_name my_hostname.com; 
    
    location / {
            proxy_pass http://123.123.123.1:$server_port$uri;
            proxy_set_header Host $host;
    }
}

Hope helps you, Sergio Turpín

Hi @LittleTurquoiseShip,

You can add the redirect in your website’s Nginx config, in your main server block for port 80 and 443, you can add the something like the following:

  1. return 301 $https://www.new_host.com$request_uri;

This redirect needs to be somewhere around your server_name(right under it for an example).

The file you can edit is /etc/nginx/sites-enabled/Domain-Name.conf where Domain-name.conf is your actual conf file. It can be named a lot of things.