Report this

What is the reason for this report?

How To Redirect IP Reverse Proxy Nginx To New IP Nginx

Posted on April 21, 2022

Can help me for How To Redirect IP Reverse Proxy Nginx To New IP Nginx ? Thanks For your 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!

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,

In order to do a redirect to another IP address, all you need to do is add a simple snippet of code in your Nginx config file:

server {
   listen 80 default_server;
   listen [::]:80 default_server;
   server_name domain.com www.domain.com;
   
   return 301 IPAddress;
}

Alternatively, if you want to redirect as reverse proxy (to another port), what you can do is

server {
    listen 80 default_server;
    server_name domain.com;


    location / {
            proxy_pass http://123.123.123.1:41002/$uri;
            proxy_set_header Host $host;
    }
}

So, first you’ll need to change domain.com with your actual domain, 123.123.123.1 with the IP address you want to redirect it to as well as the port 41002 to your needs.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.