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

编程入门 行业动态 更新时间:2024-10-25 23:32:17
本文介绍了Nginx:如何让重写规则忽略文件或文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

I use Nginx to serve a SPA (Single Page Application), in order to support HTML5 History API I have to rewrite all deeper routes back to the /index.html, so I follow this article and it works! This is what I put in nginx.conf now:

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

但是有一个问题,我有一个 / assets 根目录下的目录包含所有的css,js,images,fonts东西,我不想重写这些url,我只是想忽略这些资产,我想怎么办?

However there's one problem, I have an /assets directory under the root contains all the css, js, images, fonts stuffs, I don't want to rewrite these urls, I just want to ignore these assets, how am I suppose to do?

推荐答案

将重写放入一个位置并使用其他位置 s作为资产/动态网址/等。

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

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

更多推荐

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

本文发布于:2023-11-16 18:23:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1606710.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重写   文件夹   规则   文件   Nginx

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!