【发布时间】:2019-01-11 03:01:31
【问题描述】:
我有以下配置:
server {
listen 80;
server_name localhost;
location /app {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /app/index.html?$args;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
当导航到 http://localhost:8000/app/ 时,一切都按预期工作,但是当删除尾部斜杠 (http://localhost:8000/app) 时,nginx 返回 301 状态响应,我被重定向到 http://localhost/app。
如何让 nginx 同时使用 http://localhost:8000/app/ 和 http://localhost:8000/app(带有和不带有斜杠)。
【问题讨论】:
-
当一个没有尾随
/的URI 指向一个目录时,你想让nginx做什么?目前$uri/告诉它发出3xx响应,listen指令告诉它在重定向中使用端口 80。 -
@RichardSmith 我希望localhost:8000/app 和localhost:8000/app 都指向同一个地方(index.html)
-
重定向是由
try_files语句中的$uri/引起的。你可以删除它。 -
@RichardSmith,你是不是建议只放
try_files $uri /app/index.html?$args;?你能把它作为答案发布吗 - 它被排除在外
标签: nginx reverse-proxy