自动索引NGINX 403错误

时间:2018-06-08 21:10:22

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

我想让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

我在俯瞰什么?

1 个答案:

答案 0 :(得分:0)

需要在服务器上方的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
...