Angular Nginx位置不工作

Angular Nginx位置不工作,angular,nginx,Angular,Nginx,我正在尝试配置我的nginx服务器。我希望当我尝试访问“ipaddress/dist/任何内容”时,所有请求都可以重定向到“ipaddress/dist/index.html”。这是Angular2的布线要求。然而,我只能找到404页。“try_files”或“location/dist”似乎不起作用。怎么了?谢谢。签出指令 server { listen 80; server_name _; access_log /data/wwwlogs/access_nginx.log combined;

我正在尝试配置我的nginx服务器。我希望当我尝试访问“ipaddress/dist/任何内容”时,所有请求都可以重定向到“ipaddress/dist/index.html”。这是Angular2的布线要求。然而,我只能找到404页。“try_files”或“location/dist”似乎不起作用。怎么了?谢谢。

签出指令

server {
listen 80;
server_name _;
access_log /data/wwwlogs/access_nginx.log combined;
root /data/wwwroot/default;
index index.html;

location /dist {
    try_files $uri $uri/ /dist/index.html;
}
签出指令

server {
listen 80;
server_name _;
access_log /data/wwwlogs/access_nginx.log combined;
root /data/wwwroot/default;
index index.html;

location /dist {
    try_files $uri $uri/ /dist/index.html;
}

你的例子行得通!也许您忘了用新配置重新加载nginx服务?

您的示例很有效!也许您忘了用新配置重新加载nginx服务?

谢谢您的回答。直接重定向似乎会丢失两级路由地址。Angular提供的解决方案是使用“位置”和“try_文件”,但我的不起作用。当nginx找不到“$uri”时,它不会进入“try_files”的最后一个参数。你能试试location/{…}吗?不,试试这个
location/{try_files$uri/dist/index.html;}
它说了什么?是的,我试过了,当我访问“www.xxx.com/donotexist”时,它会出现404页而不是index.html。但是如果“try_files”有效,它应该被重定向到index.htmllocation/{try_files$uri/index.html;}`404页仍然出现感谢您的回答。直接重定向似乎会丢失两级路由地址。Angular提供的解决方案是使用“位置”和“try_文件”,但我的不起作用。当nginx找不到“$uri”时,它不会进入“try_files”的最后一个参数。你能试试location/{…}吗?不,试试这个
location/{try_files$uri/dist/index.html;}
它说了什么?是的,我试过了,当我访问“www.xxx.com/donotexist”时,它会出现404页而不是index.html。但是如果“try_files”有效,它应该被重定向到index.html位置/{try_files$uri/index.html;}`404页仍然出现您是否尝试设置
error_log/data/wwwwlogs/error_nginx.log debug
找出发生了什么?您是否尝试设置
错误日志/data/wwwlogs/error\nginx.log调试以了解发生了什么?