我使用Nginx来提供SPA(单页应用程序),为了支持HTML5 History API,我必须将所有更深层次的路由重写回/index.html
,所以我按照this article进行操作!这就是我现在在nginx.conf中添加的内容:
server {
listen 80 default;
server_name my.domain.com;
root /path/to/app/root;
rewrite ^(.+)$ /index.html last;
}
然而有一个问题,我在根目录下有一个/assets
目录包含所有css,js,图像,字体的东西,我不想重写这些网址,我只是想忽略这些资产,我该怎么办?
答案 0 :(得分:15)
将rewrite
放入一个location
,并将其他location
用于资产/动态网址/等。
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.
}
}