Angular 4-Nginx / Refresh显示不良页面

Ben*_*rme 5 nginx angular

我在使用Nginx的远程服务器上部署了Angular 4应用程序,并可以通过以下地址进行访问: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;
        }
    }
Run Code Online (Sandbox Code Playgroud)

似乎root /var/www在刷新期间未考虑该行。

我听到了有关try_files错误的消息,似乎我需要在某个地方添加重写。感谢帮助。

Fal*_*aly 3

尝试将其添加到您的 AppModule 中:

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

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