I've configured my Nginx server to serve an Angular app with a simple config file like so:
server {
listen 80;
listen [::]:80;
root /path/to/apps/myapp/current/dist;
access_log /path/to/apps/myapp/current/log/nginx.access.log;
error_log /path/to/apps/myapp/current/log/nginx.error.log info;
index index.html;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
location / {
try_files $uri $uri/ =404;
}
}
Everything is working smoothly as expected. Since I'm using Angular UI Router, I want all pages to be forwarded to index.html
for Angular to take control (meaning a request to example.com/users/new
should be redirected by Nginx to index.html
for Angular UI to manage) for page reloads, links, etc.
How can I make this happen?
I've tried different options such as:
server {
#implemented by default, change if you need different ip or port
#listen *:80 | *:8000;
server_name test.com;
return 301 $scheme://www.test.com$request_uri;
}
As mentioned in this response. However, I couldn't get anything similar to work for all requests.
Any suggestions would be greatly appreciated.