nginx reverse proxy to another nginx

1. Background

I encountered a problem when deploying a project recently. Alibaba Cloud parsed it to a public IP, and forwarded it by nginx of the public IP. However, when forwarding, the project is separated from the front and back ends and needs to be resolved to the xxx directory of the remote server, which is not easy to solve through an nginx forwarding. It is forwarded to the nginx port of the remote server through the first nginx, and it can be forwarded locally by the nginx of the remote server.

2. Steps

1. For example, the internal network ip of the remote server is 192.168.10.11, and the nginx of the ip public network ip server is forwarded to port 80 (nginx port) of 192.168.10.11:.
upstream config_upstream{
    
    
  server 192.168.10.11:80   max_fails=3 fail_timeout=3s weight=10;
}

server {
    
    
        listen       80;
        server_name  config.xxxx.com;

          location / {
    
    
                        proxy_next_upstream error timeout invalid_header http_500 http_503;
                        proxy_pass  http://config_upstream;
                        proxy_set_header X-Forwarded-Proto https;
                        proxy_set_header   Host             $host;
                        proxy_set_header   X-Real-IP        $remote_addr;
                        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
                        proxy_redirect     off;
                        proxy_connect_timeout      300;
                        proxy_send_timeout         300;
                        proxy_read_timeout         300;
                        #proxy_send_lowat          12000;
                        proxy_buffer_size          128k;
                        proxy_buffers              8 64k;
                        proxy_busy_buffers_size    128k;
                        proxy_temp_file_write_size 128k;
                }
    }
2. Install nginx on the remote server 192.168.10.11 for forwarding.
upstream config_upstream{
    
    
  server 127.0.0.1:9990   max_fails=3 fail_timeout=3s weight=10;
}

server {
    
    
        listen       80;
        server_name  config.xxxx.com;


          location / {
    
    
                 root /data2/java/deploy/web/disconf/html;
                 if ($query_string) {
    
    
                         expires max;
                 }
            }
          location ~ ^/(api|export) {
    
    
                        proxy_next_upstream error timeout invalid_header http_500 http_503;
                        proxy_pass  http://config_upstream;
                        proxy_set_header X-Forwarded-Proto https;
                        proxy_set_header   Host             $host;
                        proxy_set_header   X-Real-IP        $remote_addr;
                        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
                        proxy_redirect     off;
                        proxy_connect_timeout      300;
                        proxy_send_timeout         300;
                        proxy_read_timeout         300;
                        #proxy_send_lowat          12000;
                        proxy_buffer_size          128k;
                        proxy_buffers              8 64k;
                        proxy_busy_buffers_size    128k;
                        proxy_temp_file_write_size 128k;
                }
}

3. Summary of the problem

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324042182&siteId=291194637
Recommended