Nginx: how to allow rewriting rules to ignore files or folders

I use Nginx to serve SPA (single page application) to support the HTML5 history API. I need to rewrite ever deeper routes back to /index.html , so I follow this article and it works! Here is what I have now added to nginx.conf:

 server { listen 80 default; server_name my.domain.com; root /path/to/app/root; rewrite ^(.+)$ /index.html last; } 

However, there is one problem: I have a /assets directory under the root containing all css, js, images, fonts stuffs, I don’t want to rewrite these URLs, I just want to ignore these assets, how do I suppose to be done?

+5
source share
1 answer

Put rewrite in one location and use other location for assests / dynamic urls / etc.

 server { listen 80 default; server_name my.domain.com; root /path/to/app/root; location / { rewrite ^ /index.html break; } location /assets/ { # Do nothing. nginx will serve files as usual. } } 
+13
source

Source: https://habr.com/ru/post/1203586/


All Articles