1

I have 2 servers, The first one contains 2 websites (located in 2 separate directories):

  1. https://example.com/site1
  2. https://example.com/site2

The second server contains 1 website in root folder (React website). Can you please help me to set up nginx on first server to make it point to the second server when user access to https://example.com.

2 Answers 2

2

Since nginx would be running in port 80, thus you need to run your web hosting content onto another port for example port 3000 from your first server.

In your nginx.config file, you would need to create an upstream where you list the server that nginx needs to re-route to: (before making changes to the file, i would recommend that you make a copy of it)

events {
    worker_connections 768;
    # multi_accept on;
 }

upstream server_banks {
  server localhost:3000; # if not localhost put the ip of the server
  server second_server_ip:portNumber;
}

server { # nginx service will operate on port 80
  listen 80; 
  server_name example.com 
 # it could your first server's ip or example.com if the domain is associated with that ip
   location / {
    proxy_pass http://server_banks;

   }

}

After you save the config, reload service && restart

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! I will check this
2

You need nginx running on both server2 and server2, then set nginx config as follow

On Server 1

#####server1####
server {
        listen 443;
        server_name example.com;

        location / {
                proxy_pass http://second_server_ip:80;
                proxy_set_header Host $http_host;
                proxy_set_header  X-Real-IP  $remote_addr;
        }
        location /site1 {
             alias /path/to_site1_dir/;
        }
      location /site2 {
             alias /path/to_site2_dir/;
        }
}

On server 2

###Server2#####

server {
        listen 80;
        server_name localhost;
        root /path/to_site_dir_for-server2;

        location / {

        }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.