鍍金池/ 問(wèn)答/PHP  Linux  數(shù)據(jù)庫(kù)/ nginx下index.php無(wú)法默認(rèn)首頁(yè)

nginx下index.php無(wú)法默認(rèn)首頁(yè)

問(wèn)題:訪問(wèn)目錄時(shí),存在index.html會(huì)默認(rèn)訪問(wèn)。不存在index.html ,但存在index.php ,會(huì)報(bào)403權(quán)限錯(cuò)誤。

服務(wù)環(huán)境(lnmp):
Red Hat 4.4.7-18
nginx1.12
php-5.5.38

nginx.conf

user  www www;

worker_processes auto;

error_log  /home/wwwlogs/nginx_error.log  crit;

pid        /usr/local/nginx/logs/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;

events
    {
        use epoll;
        worker_connections 51200;
        multi_accept on;
    }

http
    {
        include       mime.types;
        default_type  application/octet-stream;

        server_names_hash_bucket_size 128;
        client_header_buffer_size 32k;
        large_client_header_buffers 4 32k;
        client_max_body_size 50m;

        sendfile   on;
        tcp_nopush on;

        keepalive_timeout 60;

        tcp_nodelay on;

        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
        fastcgi_buffer_size 64k;
        fastcgi_buffers 4 64k;
        fastcgi_busy_buffers_size 128k;
        fastcgi_temp_file_write_size 256k;

        gzip on;
        gzip_min_length  1k;
        gzip_buffers     4 16k;
        gzip_http_version 1.1;
        gzip_comp_level 2;
        gzip_types     text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss;
        gzip_vary on;
        gzip_proxied   expired no-cache no-store private auth;
        gzip_disable   "MSIE [1-6]\.";

        #limit_conn_zone $binary_remote_addr zone=perip:10m;
        ##If enable limit_conn_zone,add "limit_conn perip 10;" to server section.

        server_tokens off;
        access_log off;

    server
    {

        listen 80 default_server;
        #listen [::]:80 default_server ipv6only=on;
        server_name _;
        index index.html index.htm index.php;
        root  /home/wwwroot/default;

        #error_page   404   /404.html;

        # Deny access to PHP files in specific directory
        #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

        include enable-php-pathinfo.conf;

        location /nginx_status
        {
            stub_status on;
            access_log   off;
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /.well-known {
            allow all;
        }
        
        location /proya/public/ {
            root   /proya/public;
            index   index.php index.html;
            #if (!-e $request_filename){
                 #rewrite ^/proya/public/(.*)$ /proya/public/index.php/$1 last;
            #}
        }

        location /xiazhimini/public/ {
            if (!-e $request_filename){
                 rewrite ^/xiazhimini/public/(.*)$ /xiazhimini/public/index.php/$1 last;
            }
        }
        
        location /minigame/public/ {
            index   index.php   index.html;
            if (!-e $request_filename){
                 rewrite ^/minigame/public/(.*)$ /minigame/public/index.php/$1 last;
            }
        }
        
        location ~ /\.
        {
            deny all;
        }

        access_log  /home/wwwlogs/access.log;
    }

    include vhost/*.conf;
}

enable-php-pathinfo.conf

location ~ [^/]\.php(\/.*)*$
{
    try_files $uri $uri/ $uri.html =404; 
    fastcgi_pass  unix:/tmp/php-cgi.sock;
    fastcgi_index index.php;
    include fastcgi.conf;
    include pathinfo.conf;
}

pathinfo.conf

set $path_info "";
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$"){
    set $real_script_name $1;
    set $path_info $2;
}  
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;

index已經(jīng)配置過(guò)了,我的想法的try_files中加入 $url.php 但是加入后沒(méi)有任何效果。所以來(lái)請(qǐng)教一下。

回答
編輯回答
撿肥皂

很好玩的是,我在服務(wù)器器這邊的的url如果重復(fù)兩次/index.php
形如:

http://localhost/index.php/index.php/home/test/test

則$_SERVER['PHP_SELF']的打印結(jié)果為

/index.php/home/test/tes
2018年1月11日 22:19