【问题标题】:nginx loading CSS/JS incorrectly when navigating to routes with more than one slash导航到带有多个斜杠的路由时,nginx 错误地加载 CSS/JS
【发布时间】: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;
    }
}

【问题讨论】:

标签: nginx static-site


【解决方案1】:

原来是 html-webpack-plugin 没有在资产前面放置 /,因为输出中没有设置 publicPath

在此处查看答案:html-webpack-plugin and webpack 2: no starting slash '/'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-06
    • 1970-01-01
    • 2012-11-16
    • 1970-01-01
    • 2017-07-04
    • 2018-03-30
    • 2021-09-15
    相关资源
    最近更新 更多