nginx转发http请求

时间:2025-03-19 21:30:33

原路径: /callback/test/test?username=xx
转发到:http://10.1.9.1:8088/callback/test/test?username=xx

配置如下:

server {
        listen       80;
        server_name ;

       # 匹配callback
        location /callback/ {
            proxy_pass http://10.1.9.1:8088;
        }

		# 默认其他
        location / {
           proxy_pass http://10.2.2.1:8088;
           # root   html;
           # index   ;
        }
		
		}

注意:在配置中http://10.1.9.1:8088,后面不用加任何目录,/callback/test/test,这一串都不需要加,/ 符号也不需要,
这是因为proxy_pass参数中如果不包含url的路径,则会将location的pattern识别的路径作为绝对路径。
重启:
./nginx -s reload

参考:/nginx/