How to configure nginx for static Angular UIs

In order to make Angular UIs work with nginx, you have to load index.html for any URL where you would otherwise return 404 in order to allow routing to work:

example.txt
location / {
  try_files $uri $uri$args $uri$args/ /index.html;
}

Full example for default site with API:

example.txt
server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/html;

        index index.html;

        server_name MyServer;

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

        location /api {
                proxy_pass http://localhost:8080;
        }
}

 


Check out similar posts by category: Nginx