Nginx:如何让重写规则忽略文件或文件夹

nig*_*ire 7 html5 nginx

我使用Nginx来提供SPA(单页应用程序),为了支持HTML5 History API我必须重写所有更深层次的路由/index.html,所以我按照这篇文章进行操作!这就是我现在放在nginx.conf中的内容:

server {
    listen 80 default;
    server_name my.domain.com;
    root /path/to/app/root;

    rewrite ^(.+)$ /index.html last;
}
Run Code Online (Sandbox Code Playgroud)

但是有一个问题,我/assets在根目录下有一个包含所有css,js,图片,字体的东西,我不想重写这些网址,我只是想忽略这些资产,我该怎么办呢?

Ale*_*Ten 15

放入rewrite一个location并使用其他locations作为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.
    }
}
Run Code Online (Sandbox Code Playgroud)