I have the following config:
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
?
nginx
做什么?目前,$uri/
告诉它发出3xx
响应,而listen
指令告诉它在重定向中使用端口80。 - Richard Smithtry_files
语句中的$uri/
引起的。你可以将其删除。 - Richard Smithtry_files $uri /app/index.html?$args;
吗?您能将其发布为答案-以便被接受。 - vlio20