location规则与proxy_pass关系

在配置Nginx时遇到一个错误,提示proxy_pass不能在使用正则表达式的location中包含URI部分。原因是proxy_pass后的URL不能有路径。修正方法是将proxy_pass设置为`http://localhost:8080`,移除'/shop_goods'。这样可以避免错误并确保配置正确。
摘要由CSDN通过智能技术生成

启动nginx时会报以下错误,原因是在给nginx配置正则表达式的时候proxy_pass是不可以有uri的。

nginx: [emerg] "proxy_pass" cannot have URI part in location given by regular expression, or inside named location, or inside "if" statement, or insid

我的nginx配置如下:

location ~* \.(jsp|do)$ 

  { 

            index index.jsp; 

            proxy_pass http://localhost:8080/shop_goods;  

            proxy_set_header X-Real-IP $remote_addr;  

        }

为什么会报错呢?

因为location 使用了正则表达式(\.(jsp|do)$),而且proxy_pass中包含了URI part(shop_goods).错误提示的意思是:

如果location包含了正则表达式,则 "proxy_pass"不能包含URI part(shop_goods).

找到原因后,修改如下:

location ~* \.(jsp|do)$  

  { 

        index index.jsp; 

        proxy_pass http://localhost:8080;  

        proxy_set_header X-Real-IP $remote_addr;  

    } 

注意:proxy_pass的值后面不要有斜杠,下面的是错误的:

proxy_pass http://localhost:8080/; 这里8080后面的/不能有。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值