Nginx PHP设置默认首页

0

以前一直用Java,所以默认的indexweb.xml就配置了,但是使用PHP却发现只敲IP访问,总提示nginx "403 Forbidden",配置如下:

location ~ \.php$ {
    root             /home/www/bbs;
    fastcgi_pass     127.0.0.1:9000;
    fastcgi_index    index.php;
    fastcgi_param    SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include          fastcgi_params;
}

配置了但是没有效果,其实fastcgi_index是没有作用的,因为既然以.php结尾了,那么很明确文件了,配置index就没意义了。
所以正确的配置是这样的:

location / {
    root             /home/www/bbs;
    fastcgi_pass     127.0.0.1:9000;
    fastcgi_index    index.php;
    fastcgi_param    SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include          fastcgi_params;
}

修改整个目录拦截,但是这样配置不是.php的一些静态文件也会通过PHP处理,所以最好这样配置:

location ~ \.php$ {
    root             /home/www/bbs;
    fastcgi_pass     127.0.0.1:9000;
    fastcgi_index    index.php;
    fastcgi_param    SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include          fastcgi_params;
}
 
location / {
    index index.php;
    root  /home/www/bbs;
}