I have an Angular 4 application deploy on a remote server with Nginx, and accessible with this address: http://xx.xx.xx.xx/app
. The app works well, I can navigate in my website but when I refresh one page, for example http://xx.xx.xx.xx/app/page1
, it displays the index.html page of nginx.
Nginx's pages are located in /usr/share/nginx/html
, and my app's pages are located in /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;
}
}
It seems that the line root /var/www
is not taken into account during a refresh.
I heard something about a bug with try_files, and it seems that I need to add a rewrite somewhere. Thanks for help.
Try to add this in your AppModule:
import { HashLocationStrategy, LocationStrategy } from '@angular/common';
@NgModule({
// ...
providers: [{provide: LocationStrategy, useClass: HashLocationStrategy}],
// ...
})
export class AppModule {}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With