编辑
2022-07-25
DevOps
00
请注意,本文编写于 641 天前,最后修改于 640 天前,其中某些信息可能已经过时。

目录

现象
原因分析
解决方案

在起项目用nginx反代的时候,会发现出现意料之外的301,把需要或者不需要的端口号带上。

现象

使用 vanblog 的镜像时使用-p 2333:80,那么:

  1. 使用 http://域名:2333 可以正常访问
  2. 使用 http://域名:2333/admin 无法访问,具体体现为:该请求会返回 301 重定向,Location 为 http://域名/admin

原因分析

官方文档

nginx
If a location is defined by a prefix string that ends with the slash character, and requests are processed by one of proxy_pass, fastcgi_pass, uwsgi_pass, scgi_pass, or memcached_pass, then the special processing is performed. In response to a request with URI equal to this string, but without the trailing slash, a permanent redirect with the code 301 will be returned to the requested URI with the slash appended. If this is not desired, an exact match of the URI and location could be defined like this: location /user/ { proxy_pass http://user.example.com; } location = /user { proxy_pass http://login.example.com; }

解决方案

配置文件增加:

nginx
absolute_redirect off;
如果对你有用的话,可以打赏哦
打赏
ali pay
wechat pay

本文作者:mereith

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!