0

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

我在看什么?

4

1 回答 1

-1

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

autoindex on;

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

信用在这里

我的配置现在开始:

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-06-09T07:44:15.680 回答