Nginx 500 子目录上的内部服务器错误

Nginx 500 子目录上的内部服务器错误

500 Internal Server我只在子目录上遇到错误。

例如,如果我的网站是 example.com,example.com/index.php则可以。

example.com/phpbb/index.php不起作用。它只是出现一个空白的 php 页面。HTTP
标头显示 HTTP 错误 500 内部服务器错误。

如果我输入example.com/phpbb/index.php/[any-directory]index.php则会显示根目录。

这一切都很奇怪。我尝试过搜索等,但都无济于事。尝试重新安装 nginx,但没有解决。我确定我的 DNS 配置正确。

更多规格:

  1. Nginx返回一个HTTP 200 OK标题,但发送一个 0kb(空)PHP 文件 -> 我只看到一个空白的屏幕
  2. 当我进入子目录时,主网站会加载。例如:如果我进入example.com/blog/,而不是生成404 错误example.com加载。
  3. Nginx忽略.php子目录中的所有文件。HTML、CSS、JS 运行良好。
  4. 没有生成错误日志。即使 php 没有加载,错误日志也是空的。
  5. PHP5-FPM在主网站上运行良好(example.com
  6. 我使用 SSL(链)

我的 Nginx 配置(/sites-available/example.com)

server {
    server_name www.example.com;
    return 301 https://example.com$request_uri;
}

server {
    listen 443;
    listen 80;
    #listen   80; ## listen for ipv4; this line is default and implied
    #listen   [::]:80 default_server ipv6only=on; ## listen for ipv6

    root /var/www/example.com/public_html;
    index index.html index.php index.htm;

    ssl on;
    ssl_certificate /etc/nginx/ssl/cert.pem;
    ssl_certificate_key /etc/nginx/ssl/ssl.key;

    ssl_session_timeout 5m;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS;
    ssl_prefer_server_ciphers on;
    ssl_stapling on;
    resolver 8.8.8.8;
    add_header Strict-Transport-Security max-age=63072000;

    # Make site accessible from http://localhost/
    server_name example.com;

    location ~* \.(jpg|jpeg|png|gif|ico|css|js|bmp)$ {
        expires 365d;
        add_header Cache-Control public;
    }

    if ($scheme = http) {
        return 301 https://example.com$request_uri;
    }

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ /index.php;
        # Uncomment to enable naxsi on this location
        # include /etc/nginx/naxsi.rules
    }


    if ($http_user_agent ~ (musobot|screenshot|AhrefsBot|picsearch|Gender|HostTracker|Java/1.7.0_51|Java) ) {
        return 403;
    }

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

    location /doc/ {
        alias /usr/share/doc/;
        autoindex on;
        allow 127.0.0.1;
        allow ::1;
        deny all;
    }

    # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
    #location /RequestDenied {
    #   proxy_pass http://127.0.0.1:8080;    
    #}

    #error_page 404 /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/www;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

        # With php5-cgi alone:
        fastcgi_pass 127.0.0.1:9000;
        # With php5-fpm:
        #fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include /etc/nginx/fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

                fastcgi_buffer_size 128k;
                fastcgi_buffers 256 16k;
                fastcgi_busy_buffers_size 256k;
                fastcgi_temp_file_write_size 256k;
                fastcgi_read_timeout 240;

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny all;
    }
    }
    }

nginx.conf

user www-data;
worker_processes 1;
pid /var/run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ## Block spammers and other unwanted visitors  ##
    include /etc/nginx/blockips.conf;

    fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=microcache:10m max_size=1000m inactive=60m;

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 100;
    types_hash_max_size 2048;
    server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # Logging Settings
    ##

    access_log off;
    error_log /var/log/nginx/error.log;

        ssl_session_cache    shared:SSL:10m;
        ssl_session_timeout  10m;
        ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS;
        ssl_prefer_server_ciphers on;

        ##
        # File Cache Settings
        ##

        open_file_cache          max=5000  inactive=5m;
        open_file_cache_valid    2m;
        open_file_cache_min_uses 1;
        open_file_cache_errors   on;

    ##
    # Gzip Settings
    ##

    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/x-js text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # nginx-naxsi config
    ##
    # Uncomment it if you installed nginx-naxsi
    ##

    #include /etc/nginx/naxsi_core.rules;

    ##
    # nginx-passenger config
    ##
    # Uncomment it if you installed nginx-passenger
    ##

    #passenger_root /usr;
    #passenger_ruby /usr/bin/ruby;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;

答案1

我遇到过这种情况。我所做的就是改变目录。因此,如果您的 public_html 位于 /var/www/example.com 下,它将是这样的:

chown -R www-data:www-data /var/www/example.com

其中 www-data 是 nginx 的用户名和组。

答案2

我不知道为什么索引指令似乎不起作用。

我可以通过将 index.php 添加到 try-file 指令来解决该问题:

try_files   $uri $uri/ $uri/index.php;

相关内容