Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度4-Nginx/刷新显示错误页面_Angular_Nginx - Fatal编程技术网

Angular 角度4-Nginx/刷新显示错误页面

Angular 角度4-Nginx/刷新显示错误页面,angular,nginx,Angular,Nginx,我有一个Angular 4应用程序部署在带有Nginx的远程服务器上,可以通过以下地址访问:http://xx.xx.xx.xx/app。该应用程序运行良好,我可以在我的网站中导航,但当我刷新一个页面时,例如http://xx.xx.xx.xx/app/page1,显示nginx的index.html页面 Nginx的页面位于/usr/share/Nginx/html,而我的应用程序的页面位于/var/www/app nginx.conf server { listen

我有一个Angular 4应用程序部署在带有Nginx的远程服务器上,可以通过以下地址访问:
http://xx.xx.xx.xx/app
。该应用程序运行良好,我可以在我的网站中导航,但当我刷新一个页面时,例如
http://xx.xx.xx.xx/app/page1
,显示nginx的index.html页面

Nginx的页面位于
/usr/share/Nginx/html
,而我的应用程序的页面位于
/var/www/app

nginx.conf

    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root /usr/share/nginx/html;
        include /etc/nginx/default.d/*.conf;                                                */

        location /app {
            root /var/www;
            try_files $uri $uri/ /index.html;
        }
    }
在刷新期间,似乎没有考虑行
root/var/www


我听说try_文件有一个bug,似乎我需要在某个地方添加一个重写。谢谢您的帮助。

尝试将此添加到AppModule中:

import { HashLocationStrategy, LocationStrategy } from '@angular/common';

@NgModule({
    // ...
    providers: [{provide: LocationStrategy, useClass: HashLocationStrategy}],
    // ...
})
export class AppModule {}

尝试以下方法:location~^/app/(.*)$而不是/app。这确保它在任何子页面上都是匹配的,不仅仅是/app您是否尝试将其更改为
root/var/www/app
尝试使用文件$uri$uri//app/index.html?@eesdil感谢您的建议,但这不会改变任何事情。@请减少您的第二个建议不起作用。但第一个更有趣。现在刷新效果很好,但当我访问我的网站时,我会直接在我的应用程序上重定向,我不想这样。所以我试着只写
root/var/www但是行为恢复到以前的状态…您应该更改为
location/app/
(额外的斜杠)。我想你可以忽略我的第一个评论。。。这很奇怪,由于
/#/
的原因,URL有点影响,但对用户来说它似乎是不可见的。你能解释一下它是怎么工作的吗?谢谢你可以在这里找到更多的解释: