nginx反向代理,首页重定向自动添加端口导致访问异常
问题:使用nginx反向代理,首页重定向到前端静态资源目录时自动添加端口 8001导致无法访问。
nginx版本1.16.1,配置内容如下:
server
{
listen 80;
server_name pifa.test;
index index.php index.html;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://192.168.251.8:8001;
}
}
被代理配置:
server
{
listen 8001;
server_name 192.168.251.8;
index index.php index.html;
root /www/wwwroot/kpi/public;
location ~ [^/]\.php(/|$)
{
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi-73.sock;
fastcgi_index index.php;
include fastcgi.conf;
include pathinfo.conf;
}
}
跳转的前端目录:
1、访问首页 pifa.test 打印内容正常
代码如下:
public function wellcome()
{
dd(redirect('/app/kpi/')->content());
return redirect('/app/kpi/');
}
打印内容如下:
2、移除打印代码后,访问首页 pifa.test 就会自动加上端口 8001 变成 pifa.test:8001/app/kpi 导致无法访问,页面截图如下:
手动移除端口后访问 pifa.test/app/kpi 是正常的,页面截图如下:
推荐文章: