为了支持HTML5历史记录API,我使用Nginx来提供SPA(单页应用程序),我必须将所有更深层的路由重写回/index.html
,因此我可以按照本文进行操作!这就是我现在放在nginx.conf中的内容:
server {
listen 80 default;
server_name my.domain.com;
root /path/to/app/root;
rewrite ^(.+)$ /index.html last;
}
但是,有一个问题,我/assets
在根目录下有一个包含所有CSS,JS,图像,字体的目录,我不想重写这些URL,我只想忽略这些资产,我应该怎么做?
放入rewrite
一个location
并使用其他location
sassest / 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.
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句