NGINX, proxy_pass and SPA routing in HTML5 mode
The solution that works for me is to add the directives proxy_intercept_errors
and error_page
to the location /
in NGINX:
server { listen 80; ... location / { proxy_pass http://spa-server/; proxy_intercept_errors on; error_page 404 = /index.html; } location /other/ { proxy_pass http://other/; } ...}
Now, NGINX will return the /index.html i.e. the SPA from the spa-server
whenever an unknown URL is requested. Still, the URL is available to Angular and the router will immediately resolve it within the SPA.
Of course, now the SPA is responsible for handling "real" 404s. Fortunately, this is not a problem and a good practice within the SPA anyway.
UPDATE: Thanks to @dan