简体   繁体   中英

nginx serves 403 error when accessing directories

My server has roughly this arborescence:

www
 |-index.php
 |foo
   |-index.php
   |-bar.php

I can access to /index.php , but accessing to / , /foo or anything else result in a 403. I've tried various config, but none of them is working.

My nginx.conf file:

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;

    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    gzip on;
    gzip_disable "msie6";
    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_buffers 16 8k;
    gzip_http_version 1.1;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    server {
        listen         80;
        server_name    localhost;
        root /var/www/html;

        location / {
            root      /var/www/html;
            #try_files $uri /index.php$is_args$args;
        }

        location ~ \.php$ {

            fastcgi_pass   web_fpm:9000;
            fastcgi_index index.php                                                                                                             
            fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name; 
            include        fastcgi_params;
        }
    }
}

If I uncomment the commented line, any request serves /index.php, so it's no good.

I've found the solution: setting the index. Here is the snippet:

server {
    listen         80;
    server_name    localhost;
    root /var/www/html;
    autoindex on;

    location / {
        index index.php index.html;
    }

    location ~ \.php$ {
        fastcgi_pass   web_fpm:9000;
        fastcgi_index  index.php;
        fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
        include        fastcgi_params;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM