【发布时间】:2020-09-18 15:09:42
【问题描述】:
当您导航到具有多个斜杠的任何路线时,我遇到了 nginx 为我的静态网站文件(CSS 和 JS)提供服务的问题。例如,example.com/test 有效,但 example.com/test/test 会尝试从 example.com/test/ 加载 css/js {.css|.js} 而不是根目录。
对于上下文,我在这个网站上使用 React 和 ReactRouter。
nginx 配置
server {
listen 80;
server_name example.com;
root /var/www/example.com;
index index.html;
rewrite ^.*$ /index.html;
location / {
try_files $uri /index.html;
}
}
【问题讨论】:
-
你在哪里指定CSS/JS文件的名字。你需要在前面放一个
/。 -
是的,这就是问题所在。我在这里找到了解决方案:stackoverflow.com/questions/43191569/…
标签: nginx static-site