1

I'm getting a 500 Internal Server error only on sub directories.

For example, If my website is example.com, example.com/index.php works.

But example.com/phpbb/index.php doesn't work. It just turns up a blank php page.
The HTTP header shows HTTP error 500 Internal Server error.

If I enter example.com/phpbb/index.php/[any-directory], index.php of root directory shows.

This is all very strange. I have tried searching etc but nothing worked. tried re-installing nginx but not fixed. I'm sure I got the DNS configured right.

More specifications :

  1. Nginx returns a HTTP 200 OK header but sends a 0kb(Empty) PHP file -> I only see a blank white screen
  2. When I go to subdirectories, the main website loads. Ex: If I go into example.com/blog/, instead of generating a 404 error, example.com loads.
  3. Nginx ignores all .php files in subdirectory. HTML and CSS, JS works fine.
  4. No error log is generated. Error log is empty even after the php not loading.
  5. PHP5-FPM works fine on the main website(example.com)
  6. I use SSL(Chain)

My Nginx Config (/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/*;
vsync
  • 103
  • 4
juyoung518
  • 11
  • 1
  • 1
  • 4
  • Are there any relevant messages in your log files ? – user9517 May 22 '14 at 10:42
  • @lain no, there were no error logs at all. I checked php5-fpm logs too, but same, no error log. – juyoung518 May 22 '14 at 10:46
  • I guess error log isn't generated since Nginx generates a HTTP 200 OK response even though the PHP doesn't load. – juyoung518 Jun 09 '14 at 00:15
  • you say that php5-fpm logs have been checked but from your vhost config you are also declaring fastcgi_pass ports and a socket connection to php-fpm. what is the actual site running in terms, nginx with php-fpm or phpfastcgi? Can you confirm you can load a phpinfo file correctly? it also looks like you are declaring the servname_variable twice in the vhost config? my advice for now would be simplify your vhost and get the site running then add in the other config declarations as you go to determine what works and what doesnt – seanl Sep 11 '14 at 21:49

2 Answers2

1

I experienced this. What I did was to chown the directory. So, if your public_html is under /var/www/example.com , it would be something like this:

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

With www-data is username and group of nginx.

0

I don't know why the index-directive does not seem to work.

I could work around the problem by adding the index.php to the try-file directive:

try_files   $uri $uri/ $uri/index.php;
jonas_jonas
  • 101
  • 1