【问题标题】:NGINX 403 error with autoindex自动索引的 NGINX 403 错误
【发布时间】:2018-06-08 21:10:21
【问题描述】:

我想让 NGINX 对目录 (\var\www\HTML\archive) 进行自动索引。这是在树莓派上。

这是与用户、服务器和位置相关的 NGINX.conf 位

#user www-data;
#user nginx;
user pi;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
...
server{
    listen 80;
    root /var/www/html;
    index index.html;

    location /archive/ {
       root /var/www/html;
       index index.html;
       autoindex on;
       }

    }

顺便说一句,我尝试了所有不同的用户 - 包括 root!

在我的错误日志中:

2018/06/08 23:35:07 [error] 22477#22477: *2 directory index of "/var/www/html/archive/" is forbidden, client: 10.0.0.6, server: _, request: "GET /archive/ HTTP/1.1", host: "10.0.0.16"

但我完成了所有的 chmod g+s、chmod 644 文件等操作。

pi@fridge-monitor:/var/www/html $ ls -al
total 24
drwxrwsr-x 4 root nginx 4096 Jun  8 11:57 .
drwxrwsr-x 3 root nginx 4096 Jun  2 18:41 ..
drwxr-sr-x 2 pi   nginx 4096 Jun  8 12:59 archive
drwxr-sr-x 2 pi   nginx 4096 Jun  8 10:53 dynamic
-rw-r--r-- 1 pi   nginx 2653 Jun  8 10:50 index.html

pi@fridge-monitor:/var/www/html $ ls -al archive
total 168
drwxr-sr-x 2 pi   nginx  4096 Jun  8 12:59 .
drwxrwsr-x 4 root nginx  4096 Jun  8 11:57 ..
-rw-r--r-- 1 pi   nginx 38113 Jun  8 12:41 1d.png
-rw-r--r-- 1 pi   nginx   366 Jun  8 12:41 table.html

我相信上面的目录也可以:

pi@fridge-monitor:/var/www/html $ namei -l /var/www/html/archive
f: /var/www/html/archive
drwxr-xr-x root root  /
drwxr-xr-x root root  var
drwxrwsr-x root nginx www
drwxrwsr-x root nginx html
drwxr-sr-x pi   nginx archive

可以看到 /archive/ 中的文件,例如,如果我转到 10.0.0.16/archive/1d.png,则显示图形。

在其他帖子中遵循了一些步骤:

[pid  4222] stat64("/var/www/html/archive/", {st_mode=S_IFDIR|S_ISGID|0755, st_size=4096, ...}) = 0

[pid  4222] stat64("/var/www/html/archive/", {st_mode=S_IFDIR|S_ISGID|0755, st_size=4096, ...}) = 0

[pid  4222] stat64("/var/www/html/archive/index.html", 0x7efe1750) = -1 ENOENT (No such file or directory)

[pid  4222] stat64("/var/www/html/archive", {st_mode=S_IFDIR|S_ISGID|0755, st_size=4096, ...}) = 0

[pid  4222] stat64("/var/www/html/archive/index.htm", 0x7efe1750) = -1 ENOENT (No such file or directory)

[pid  4222] stat64("/var/www/html/archive/index.nginx-debian.html", 0x7efe1750) = -1 ENOENT (No such file or directory)

[pid  4222] stat64("/var/www/html/archive/", {st_mode=S_IFDIR|S_ISGID|0755, st_size=4096, ...}) = 0

[pid  4222] stat64("/var/www/html/archive/", {st_mode=S_IFDIR|S_ISGID|0755, st_size=4096, ...}) = 0

我忽略了什么?

【问题讨论】:

  • 您的配置中是否还有其他server 块?您可以使用nginx -T查看nginx实际正在读取的文件
  • 谢谢@Richard。我不这么认为,但我对运行服务器完全陌生。我将发布整个配置(为清楚起见删除了 cmets:
  • 另外我运行了 nginx -T 它确实显示了我一直在编辑的配置文件。我不知道它是否相关,但在配置文件之后它列出了一堆模块并且自动索引不在其中。有没有可能没有安装??
  • 您在编辑配置文件后重新启动nginx?另外,请编辑您的问题并在此处添加相关信息。
  • 是的,我每次都在重新启动。我其实有一个解决方案...

标签: nginx permissions http-status-code-403 mod-autoindex


【解决方案1】:

需要在服务器上方的html部分添加命令!

autoindex on;

现在工作正常! 感谢@RichardSmith 的善意

信用here

我的配置现在开始:

user pi;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;
    autoindex on;    **** <--- HERE
...

【讨论】:

  • 请注意,这似乎已为整个站点打开了自动索引。这对我来说并不重要,但请注意!
猜你喜欢
  • 2018-10-16
  • 2016-06-19
  • 2017-12-01
  • 2013-10-17
  • 1970-01-01
  • 2015-02-02
  • 1970-01-01
  • 1970-01-01
  • 2013-07-19
相关资源
最近更新 更多