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

问题描述 投票:0回答:1

我想使用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

nginx centos7 httpd.conf http-status-code-403
1个回答
0
投票

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

已删除:

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

添加

        root          /opt/chocolatey/;
        autoindex      on;

在服务器{}指令下

© www.soinside.com 2019 - 2024. All rights reserved.