How to fix an unknown internal server error (500) Nginx is giving me?

March 19, 2015 76.2k views
Nginx CentOS

Nginx is giving me a 500 error that's driving me crazy. First of all I have a personalsite.conf archive inside /etc/nginx/conf.d/ where I have my server block.

This is my server block configuration:

server {
    listen       80;
    server_name  personalsite.me;

    charset UTF-8;
    access_log  /var/log/nginx/personalsite.access.log  main;
    error_log /var/log/nginx/personalsite.error.log;

    root   /usr/share/nginx/html/personalsite;
    index index.php index.html index.htm;

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html/;
    }

    location ~ \.php$ {
        try_files $uri =404;
        include fastcgi_params;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

Plus nginx user have its proper permissions asigned over /usr/share/nginx/html/personalsite/.

The thing is Nginx is giving me a 500 error when I try to browse personalsite.me, and the funny thing is that I know that because I checked the personalsite.access.log and see it, because the brower just goes blank. By unknown reasons Nginx is unable to show me its 500 error page, properly declared in the server block as you can see.

Another odd thing is that personalsite.error.log is in blank, it records nothing.

Also I have that domain declared with its IP in my /etc/hosts archive. So I really have no idea what's happening here.

Everything is running CentOS 7 over a droplet here in Digital Ocean.

8 comments
  • Can you paste error log file? why you think you require to change /etc/hosts file? is that in your droplet /etc/hosts file?

    Also nginx doesn't show 500 error page, if you use Chrome press F12 to show the console, you will see the error state on network tab.

  • Actually, since a 500 error is too ambiguous, it could be my nginx config or could be related to the website content.

    I replaced the site content with a simple phpinfo.php file, and this time it shows perfectly in the browser. That helped me to understand that my Nginx is ok. The problem is with the website I'm trying to run. The website I'm trying to run uses Yii Framework. I checked Yii's official wiki and it says:

    Software is nginx, php-fpm (php5-fpm). For performance, it's recommended to run php-fpm in SOCKET mode, instead of accessing via IP:PORT.

    I'm using Nginx exactly like that as you can see. So I have no idea why it gives me a 500 error and wont write on the error.log once I put the content back.

  • Try to check /var/log/nginx/error.log if exist, if not, remove the line where you are assigning a diferent log file so he uses the standard one at /var/log/nginx/error.log

    Also the socket thing is a recommendation and some people can recommend you to use tcp, but still should not be related to your error if you phpinfo.php is working.

    Does this Yii requires any kind of cute urls or something similar?

    try adding " fastcgiintercepterrors on; " to the php block and check error log.

  • I am having the same issue, do you remember how you've fixed this?

  • I use vestacp control panel, and my script runs on nginx. All script that runs for 90 seconds or longer cause internal server error (500), all script run time limit for have been set to longer than 90 seconds (I don't know if I missed some setting somewhere).. please help.

  • In my case problem was with permission level of wp-config file and that was recorded at /var/log/nginx/error.log

1 Answer

This question was answered by @EpicCDN:

Try to check /var/log/nginx/error.log if exist, if not, remove the line where you are assigning a diferent log file so he uses the standard one at /var/log/nginx/error.log

Also the socket thing is a recommendation and some people can recommend you to use tcp, but still should not be related to your error if you phpinfo.php is working.

Does this Yii requires any kind of cute urls or something similar?

try adding " fastcgiintercepterrors on; " to the php block and check error log.

View the original comment

Have another answer? Share your knowledge.