Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

For example, If my website is, works.

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

If I enter, the index.php of my root directory shows up.

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, instead of generating a 404 error, 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( 6) I use SSL(Chain)

My Nginx Config


server {
    return 301$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/;
    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_prefer_server_ciphers on;
    ssl_stapling on;
    add_header Strict-Transport-Security max-age=63072000;

    # Make site accessible from http://localhost/

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

    if ($scheme = http) {
        return 301$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_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 ::1;
        deny all;

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

    #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
    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:
        # 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;


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

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_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/*;
share|improve this question
Are there any relevant messages in your log files ? – Iain 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 9 '14 at 0: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

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

chown -R www-data:www-data /var/www/

With www-data is username and group of nginx.

share|improve this answer

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;
share|improve this answer
Sorry that didn't work. Now, the index.php file doesn't even load. Nginx sends a HTTP 400 bad request. – juyoung518 Jun 9 '14 at 0:06

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.