禁止/ some / folder的Nginx 403目录索引

时间:2018-11-27 09:19:13

标签: nginx centos7 httpd.conf http-status-code-403

我想使用Nginx进行文件浏览(就像在文件浏览器中一样-没有index.html)

文件夹/ opt /巧克力内容

find
.

./ccleaner
./ccleaner/ccsetup549.exe

配置文件:

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        #root         /usr/share/nginx/html;
        root          /opt/chocolatey/;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        #location / {
        #}

        location / {
           root /opt/chocolatey/;
          autoindex on;
    }


        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

权限:chmod 755 / opt / chocolatey / * chown -R nginx:nginx / opt / chocolatey

ls -ls
total 4
4 drwxr-xr-x. 4 nginx nginx 4096 Nov 27 08:29 chocolatey

在error.log文件中:

请求:“ GET / HTTP / 1.1”,主机:“ 192.168.1.13” 2018/11/27 08:44:21 [错误] 9733#0:* 2禁止“ / opt / chocolatey /”目录索引

Selinux已禁用

设置chmod -R o+x /opt/chocolatey

1 个答案:

答案 0 :(得分:0)

已解决:必须更改配置文件:

已删除:

location / {
           root /opt/chocolatey/;
          autoindex on;
    }

已添加

        root          /opt/chocolatey/;
        autoindex      on;

在服务器{}指令下