nginx proxy_pass末尾神奇的/

http://otherserver;和http://otherserver/;有什么区别呢?

location /service/ {
    proxy_pass http://otherserver;
    proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
}
location /service/ {
    proxy_pass http://otherserver/;
    proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
}

同样访问:http://neverstay.com/service/add.php
前者配置,在后端的机器,收到的是http://neverstay.com/service/add.php
后者配置,在后端的机器,收到的是http://neverstay.com/add.php

如果换成下面这样,会报错:

location ~ ^/(service)/ {
    proxy_pass http://otherserver/;
    proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
}
"proxy_pass" may not have URI part in location given by regular expression, or inside named location, or inside the "if" statement, or inside the "limit_except" block in nginx.conf:

但是,这样就没问题了:

location ~ ^/(service)/ {
    proxy_pass http://otherserver;
    proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,293评论 19 139
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 174,935评论 25 709
  • 肾脏被称为人体的“清洁工”,它将人体不需要的废物和过量水分排出体外,菜宝宝提示,日常生活中的不当习惯或行为会成为“...
    鑫的传说阅读 2,187评论 0 0
  • 今天公司人事部门召开行动学习促动会
    深圳的早晨阅读 1,098评论 0 0
  • 停 每一个地上的人的灵魂 都对应一个天上的星星 停下来 多抬头看看星星 停下来 多收心等等灵魂 虽然你是你自己 但...
    姬二水阅读 3,173评论 2 4