2016-05-14 116 views
0

我的服务器大致有此树状:nginx的服务403错误

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

我可以访问/index.php,但访问到//foo或其他任何导致403我已经试过各种配置,但他们都没有工作。

nginx.conf文件:

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; 
     } 
    } 
} 

如果我取消了注释行,任何请求提供的index.php,所以一点也不好。

回答

0

我找到了解决方案:设置索引。这里是摘录:

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; 
    } 
}