reactjs - 获取 https://myurl.com/static/js/main.c6e1854c.chunk.js net::ERR_ABORTED 404(未找到)
问题描述
我正在使用 react 和 nginx 来部署我的网站。问题是我在 url 下部署了所有内容,myurl.com/path
但是当服务器尝试获取 js 文件时,它尝试从 root 获取myurl.com
,我看到了错误。
GET https://myurl.com/static/js/main.c6e1854c.chunk.js net::ERR_ABORTED 404 (Not Found)
如果我去https://myurl.com/ path /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 中的内容 - 没有加载,因为它缺少子目录路径。
解决方案
解决了问题。我只需要:
- 添加
PUBLIC_URL=https://myurl.com/path
到.env
文件; - 通过添加前缀来修改所有资产路径
path/
。
感谢大家的帮助和正确指导!
推荐阅读
- python - Pandas groupby-aggregation 在 shift() 操作后不起作用
- c# - 脚本停止更改值
- javascript - D3js:csv 与 json 读取。修改数据时的差异
- flutter - SizedBox 在 listview-Flutter 中不起作用
- python - python 十六进制有效负载转换为字节数组并转换字节序
- android - 如何以编程方式单击 Jetpack Compose 中的按钮?
- javascript - PWA HTML 按钮在 Android 中显示,但在 iOS 中不显示
- django - 外键字段未在数据库中注册
- postgresql - AWS DMS 任务失败
- pysimplegui - pysimplegui 表:表的垂直滚动条是否有获取或设置类型功能?