使用nginx和php-fpm禁止php目录索引403

时间:2018-01-07 02:47:04

标签: php apache nginx

我按照arch linux wiki上的说明使用nginx + php运行网站,而不使用apache webserver。 出于某种原因,当我尝试访问我在nginx配置中设置的目录时,我收到403禁用错误。这是配置:

server {
  server_name myserver.me;
    location /webmail {
        alias /usr/share/webapps/roundcubemail;
        access_log /var/log/nginx/roundcube_access.log;
        error_log /var/log/nginx/roundcube_error.log;
    }
    # Robots file
    location ~ ^/webmail/robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }
    # Deny Protected directories 
    location ~ ^/webmail/(config|temp|logs)/ {
         deny all;
    }
    location ~ ^/webmail/(README|INSTALL|LICENSE|CHANGELOG|UPGRADING)$ {
        deny all;
    }
    location ~ ^/webmail/(bin|SQL)/ {
        deny all;
    }
    # Hide .md files
    location ~ ^/webmail/(.+\.md)$ {
        deny all;
    }
    # Hide all dot files
    location ~ ^/webmail/\. {
        deny all;
        access_log off;
        log_not_found off;
    }
    #Roundcube fastcgi config
    location ~ /webmail(/.*\.php)$ {
        include fastcgi.conf;
        fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
        fastcgi_split_path_info ^/webmail/(.+\.php)(/.*)$;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /usr/share/webapps/roundcubemail/$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param PHP_VALUE open_basedir="/tmp/:/var/cache/roundcubemail:/usr/share/webapps/roundcubemail:/etc/webapps/roundcubemail:/usr/share/pear/:/var/log/roundcubemail";
    }
}

}

为什么我收到此错误?它说目录索引是被禁止的。我知道这是一个常见的问题,但我的PHP经验很少,特别是对于nginx。

0 个答案:

没有答案