Search code examples
nginxreverse-proxydigital-oceancloudflare

How to set nginx reverse proxy in remote server


I have one server Server-1 where my app server is running.
In Server-2 I want to set up my Nginx to act as a reverse proxy for my app server.

  1. how do I set up Nginx(in Server-2) which forwards traffic to Server-1
  2. how do I check that everything is working fine, Nginx(Server-2) is acting as a reverse proxy for my app server(Server-1)

Traffic--->Server-2(with Nginx reverse proxy)--->Server-1(with server)


Solution

  • 1) You should add location that will be redirecting all traffic from Server-2 to Server-1, e.g.:

    server {
        listen          80;
        server_name     Server-2.com;
        location / {
            proxy_pass  http://Server-1.com/;
        }
    }
    

    2) Try load http://Server-2.com page and if everything fine, you will get response from your app on Server-1.com