您的位置:首页 > 运维架构 > Nginx

nginx "proxy_pass" cannot have URI part in location given by regular expression

2017-12-22 16:07 656 查看
PS:我是在配置nginx可以访问tomcat下面的资源文件的时候,出现了这个问题,看到这篇文章,在给nginx配置正则表达式的时候proxy_pass是不可以有uri的。

在windows中使用nginx时报错:

C:\TDDOWNLOAD\nginx-1.6.0\nginx-1.6.0>nginx.exe -s reload

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

e "limit_except" block in C:\TDDOWNLOAD\nginx-1.6.0\nginx-1.6.0/conf/nginx.conf:61

 

我的nginx配置如下:

Java代码  

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).

找到原因后,修改如下:

Java代码  

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/;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐