Geo*_* C. 7 nginx reverse-proxy 301-redirect apache-2.4
每次我在浏览器中尝试 foobar.com/test 时,nginx 似乎都会将客户端重定向(301)到 foobar.com/test/。这种行为是不可接受的。代理服务器是远程 Apache Web 服务器。我曾尝试直接调用 Apache 服务器(没有代理),但它不会重定向客户端。
考虑到下面的 nginx 服务器配置,知道我应该如何解决这个问题吗?
server {
listen 80;
server_name fooBar.com;
location /test {
proxy_redirect off;
proxy_pass http://1.1.1.1:80/;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /test/ {
proxy_redirect off;
proxy_pass http://1.1.1.1:80/;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Run Code Online (Sandbox Code Playgroud)
fam*_*kin 14
根据文档,此场景有一种特殊的处理方式:
如果位置由以斜杠字符结尾的前缀字符串定义,并且请求由 proxy_pass、fastcgi_pass、uwsgi_pass、scgi_pass 或 memcached_pass 之一处理,则执行特殊处理。响应URI 等于该字符串但没有尾部斜杠的请求,带有代码301 的永久重定向将返回到附加斜杠的请求URI。如果不需要,可以像这样定义 URI 和位置的精确匹配:
Run Code Online (Sandbox Code Playgroud)location /user/ { proxy_pass http://user.example.com; } location = /user { proxy_pass http://login.example.com; }
(http://nginx.org/en/docs/http/ngx_http_core_module.html#location)
归档时间: |
|
查看次数: |
13799 次 |
最近记录: |