GET https://myurl.com/static/js/main.c6e1854c.chunk.js net :: ERR_ABORTED 404(未找到)

我正在使用react和nginx来部署我的网站。问题是我将所有内容都部署在URL myurl.com/path下,但是当服务器尝试获取js文件时,它尝试从myurl.com的根目录获取,我看到了错误。

GET https://myurl.com/static/js/main.c6e1854c.chunk.js net::ERR_ABORTED 404 (Not Found)

如果我转到https://myurl.com/ 路径 /static/js/main.c6e1854c.chunk.js-我可以访问该文件。

我找不到应该添加路径的位置,以便服务器知道正确的路径。

有什么想法吗?

我的nginx

server {
    listen       80;
    server_name  localhost;

    root   /usr/share/nginx/html;
    index  index.html index.htm;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        try_files $uri /index.html;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

我怀疑问题不是nginx,因为我可以看到部分网络加载(一些其他脚本)。但是,主要js中的内容-未加载,因为它缺少子目录 path

kim_heechul 回答:GET https://myurl.com/static/js/main.c6e1854c.chunk.js net :: ERR_ABORTED 404(未找到)

已解决的问题。我只需要:

  1. PUBLIC_URL=https://myurl.com/path添加到.env文件中;
  2. 通过添加前缀path/修改所有资产路径。

感谢大家的帮助和正确的指导!

本文链接:https://www.f2er.com/3158850.html

大家都在问