nginx 在 404 错误上显示索引

nginx 在 404 错误上显示索引

Nginx 为每个未找到的页面显示 index.php。我可以访问每个存在的页面,例如 domain.com/index.php index1.php index2.php

但尝试访问不存在的页面 blabla.php 或 /phpmyadmin

它显示index.php

有小费吗?

# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples 

server { 
    listen 80; 
    listen [::]:80;   
    return 301 https://panel.WEbsite.com$request_uri;

# rest of the all stuffs will be here 
    # we skipped to HTTPS # Includes HSTS Preload 
}   

# HTTPS server # 
server { 
    listen 443 ssl spdy; 
    keepalive_timeout   70; 
    server_name panel.WEbsite.com localhost; # www.panel.WEbsite.com; 
    server_tokens off; 
    add_header X-Frame-Options SAMEORIGIN; 
    add_header X-Content-Type-Options nosniff; 
    add_header X-XSS-Protection "1; mode=block";

    if ($host ~* ^www\.(.*)) {
        set $host_without_www $1;
        rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
        }

    #root /var/www/panel/public;
    root /var/www/panel/x2;
    index index.php index.html;

    error_page 404 /404.html;
    location  /404.html {
        internal;
    }
    error_page 500 502 503 504 /500.html;
    location = /500.html {  
    internal;
    }
    ssl on;         
    access_log off; 
    spdy_headers_comp 3;      

    ##Self Signed Certs
    #include snippets/snakeoil.conf;
    ssl_session_timeout 10m;    
    #ssl_certificate ssl/WEbsite.crt;
    ssl_certificate snippets/panelbundle.crt;
    ssl_certificate_key ssl/panel.key;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;        
    ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:ECDHE-RSA-RC4-SHA:ECDHE-ECDSA-RC4-SHA:RC4-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!3DES:!MD5:!PSK'; 

    ssl_prefer_server_ciphers on;      
    ssl_stapling on;      
    ssl_stapling_verify on;      
    ssl_session_cache shared:SSL:10m;   
    #ssl_trusted_certificate /etc/nginx/ssl/signed_cert_plus_intermediate.crt; 

    resolver 8.8.8.8 8.8.4.4 valid=86400; 

    add_header Strict-Transport-Security 'max-age=31536000; includeSubDomains; preload';         

     location / {                try_files $uri $uri/ /index.php;        }

    location ~ \.php$ {         
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000; 

        #fastcgi_pass unix:/var/run/php5-fpm.sock;                 fastcgi_param PHP_VALUE "upload_max_filesize = 100M \n post_max_size=101M";                 

        fastcgi_index index.php; 
        #fastcgi_param SCRIPT_FILENAME /var/www/panel/public$fastcgi_script_name;   
        fastcgi_param SCRIPT_FILENAME /var/www/panel/x2$fastcgi_script_name;
        fastcgi_buffer_size 128k; 
        fastcgi_buffers 256 16k; 
        fastcgi_busy_buffers_size 256k; 
        fastcgi_temp_file_write_size 256k; 

        include fastcgi_params; 

        }
}
server {

        location /phpmyadmin {
               root /usr/share/;
               index index.php index.html index.htm;
               location ~ ^/phpmyadmin/(.+\.php)$ {
                       try_files $uri =404;
                       root /usr/share/;
                       fastcgi_pass 127.0.0.1:9000;
                       fastcgi_index index.php;
                       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                       include /etc/nginx/fastcgi_params;
               }
               location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
                       root /usr/share/;
               }
        }
        location /phpMyAdmin {
               rewrite ^/* /phpmyadmin last;
        }

}     
 # if more thing exits will go here 

答案1

您的配置包括以下行

location / {                try_files $uri $uri/ /index.php;        }

这指示 NGINX 执行您所抱怨的操作。

相关内容