gpt4 book ai didi

nginx - 403 forbidden of nginx in ubuntu

转载 作者:行者123 更新时间:2023-12-04 18:02:08 25 4
gpt4 key购买 nike

我已阅读 beginner's guide of nginx :

server {
location / {
root /data/www;
}

location /images/ {
root /data;
}
}

http://localhost/images/example.png ->/data/images/example.png

http://localhost/some/example.html ->/data/www/some/example.html

所以我的nginx配置:

 server {
listen 443;
server_name localhost;
ssl on;
ssl_certificate /home/attolee/sslkey/example.crt;
ssl_certificate_key /home/attolee/sslkey/example.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ALL:!ADH:!EXPORT56:-RC4+RSA:+HIGH:+MEDIUM:!EXP;
ssl_prefer_server_ciphers on;

location / {
root /home/attolee;
index index.html;
}

location /hi/ {
root /home/attolee;
index hi.html;
}
}

我要

  1. https://host/访问/home/attolee/index.html,
  2. https://host/hi/访问/home/attolee/hi/hi.html,

现在 1 个工作,2 个失败,403 个禁止。

错误日志告诉我是 13: Permission denied

所以我检查了/home/attolee 和/home/attolee/hi/的自己和组,以及 hi.html。

drwxr-xr-x  6 attolee attolee 4096 Nov  2 17:08 attolee/
drw-rw-rw- 2 root root 4096 Nov 2 17:12 hi/
-rw-rw-rw- 1 root root 24 Nov 2 17:12 hi.html

然后检查 nginx 进程 USER 属性使用 htop 是 root。

如何解决这个问题?

最佳答案

首先,在您的示例中,您应该这样做:

root /home/attolee;
index index.html hi.html
location / {
try_files $uri $uri/ =404;
}

其次,您不需要以 root 身份运行 nginx。例如,在 nginx.conf 中,您可以将其更改为 www-data。您必须将/home/hi 移动到/home/attolee/中,并使用正确的所有者设置/home/attolee。

关于nginx - 403 forbidden of nginx in ubuntu,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33475016/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com