我正在使用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 。