I\'m serving Angular 2 application with nginx using location section this way:
location / {
try_files $uri $uri/ /index.html =404;
}
try_file
I got the following setup working for my Angular apps, includes changes to index.html and nginx configuration:
index.html
nginx.conf
location / {
try_files $uri $uri/ /index.html;
}
location ~ \.html$ {
add_header Cache-Control "private, no-cache, no-store, must-revalidate";
add_header Expires "Sat, 01 Jan 2000 00:00:00 GMT";
add_header Pragma no-cache;
}
Works both when user navigates to "site.com" and "site.com/some/url" or "site.com/#/login". The "index.html" changes are to be on the safe side mainly.