nginx - Nginx 更改根路径后返回 404
问题描述
我已经在我的 Digital Ocean droplet 上安装了 Nginx,并且我已经为我的 react 应用程序进行了构建,现在我想将构建 index.html 文件提供给 Nginx,
/etc/nginx/sites-enabled/default
:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /root/project-name/dist;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
}
当我在浏览器中访问服务器时,我收到一条 404 消息。
路径/root/project-name/dist
有效:
如果我将根路径更改为:
root /var/www/html;
然后我会显示默认的 Nginx 页面:
和文件夹都在同一路径中root
:var
那么为什么我不能将我的根目录指向不同的文件夹呢?
解决方案
解决了错误。
步骤 1. 阅读日志(!!)
我的 nginx 日志位于/var/log/nginx/
. 显示error.log
:
2021/10/04 18:18:41 [crit] 1565#1565: *3 stat() "/root/project-name/dist/" 失败(13:权限被拒绝),客户端:82.73.195.213,服务器:_ ,请求:“GET / HTTP/1.1”,主机:“104.248.82.123”
步骤 2. 更改对文件夹的访问权限:
chmod +x /root/
chmod +x /root/project-name
chmod +x /root/project-name/dist
推荐阅读
- python - 在 tkinter 中将文本添加到自定义圆形按钮
- jenkins - 在没有 Artifactory 插件的情况下将 Jenkins 凭据传递给 Artifactory
- javascript - 是什么导致我的支付网关设置失败?
- asp.net - 将字符串与配置文件中的 Octopus 变量连接起来
- ios - 尝试将图像存储为 base64 并使用它
- flutter - Flutter Web - 播放 uint8list n 视频播放器
- javascript - 来自外部geojson的标记不在MapBox中呈现
- java - 如何有效地将用户输入的字符转换为 Java 中的数值(双精度)?
- c# - 保存/加载值和颜色到 txt/xml
- python - Python Beautiful Soup html.parser 不返回任何内容