Implement nginx proxy on server A to nginx on server B

Usage scenario: By accessing server A, forward and request server B. This scenario needs to be implemented through nginx.

Resource preparation, nginx is installed on both server A and server B.

Server A (192.168.50.123)
Server B (192.168.50.124)

Modify the nginx configuration file on server A, the content is as follows

   upstream config_upstream{
        # 转发的访问地址
		server 192.168.50.124:80   max_fails=3 fail_timeout=3s weight=10;
   }	
	
   server {
        listen       80;
        server_name  localhost;

        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;
        }
		
	
	
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

Server B does not need to make any modifications, just ensure it is running. By accessing 192.168.50.123:80, the actual access is 192.168.50.124:80

Insert image description here

Guess you like

Origin blog.csdn.net/qq_45752401/article/details/125487516