javascript - How to redirect all Angular request to index.html in Nginx -


i have create simple nginx config file server angular 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;   } } 

and works fine expected. because i'm using angular ui router, i'd forward pages index.html angular take on (so request example.com/users/new redirect nginx index.html, angular ui handle it) pages reloads, links, etc.

how can achieve this?

i've playing around options like:

server {     #implemented default, change if need different ip or port     #listen *:80 | *:8000;     server_name test.com;     return 301 $scheme://www.test.com$request_uri; } 

as specified in this answer. couldn't similar work based on requests.

suggestions appreciated.

you need add router end of try_files directive, this:

location / {     try_files $uri $uri/ /index.html; } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -