本文介绍: nginx配置规则还是有点复杂的,在此只总结下本人遇到一个坑与解决方法,具体原因还不清楚。

一、概述

nginx配置规则还是有点复杂的,在此只总结下本人遇到一个坑与解决方法,具体原因还不清楚。

二、配置没有生效的坑

1.首先,要访问url样例是:

http://10.123.123.123:8080/b/c/getInfo
		 
http://10.123.123.123:8080/a/b/c/getMsg

nginx配置规则是:

        location /b/c/ {
          proxy_set_header Host $host;
          proxy_set_header Connection close;
          proxy_pass http://10.124.124.124:8089/api/other_Systems/;
         }

2.此时,访问

http://10.123.123.123:8080/b/c/getInfo

会按照nginx配置转发到:

http://10.124.124.124:8089/api/other_Systems/getInfo

这个没有问题的。

3.但是,访问:

http://10.123.123.123:8080/a/b/c/getMsg

本来以为也可以转发到:

http://10.124.124.124:8089/api/other_Systems/getMsg

结果并不是这样,访问的还是http://10.123.123.123:8080/a/b/c/getMsg没有规则转发

三、解决方法

1.nginx需要这样配置:

        location /b/c/ {
          proxy_set_header Host $host;
          proxy_set_header Connection close;
          proxy_pass http://10.124.124.124:8089/api/other_Systems/;
         }
         
        location /a/b/c/ {
          proxy_set_header Host $host;
          proxy_set_header Connection close;
          proxy_pass http://10.124.124.124:8089/api/other_Systems/;
         }

这样,才能把:

http://10.123.123.123:8080/a/b/c/getMsg

转发到:

http://10.124.124.124:8089/api/other_Systems/getMsg

四、后记

1.改完nginx配置文件,要找到nginx启动文件使用命令重启sudo ./nginx -s reload这个别忘了。

2.这个转发规则为什么只配置一个不行、配置两个才行,原因还不太清楚,在此先总结解决方法

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注