Nginx Tip: 500 Internal Server Error Error Solution

  
                  

This article gives you a lot of reasons for the cause of the 500 Internal Server Error error in nginx. Summary and solution analysis Need to know friends can refer to the reference

Now more and more sites are starting With Nginx, ("engine x") is a high-performance HTTP and reverse proxy server and an IMAP/POP3/SMTP proxy server. Nginx was developed by Igor Sysoev for the second-most visited Rambler.ru site in Russia, which has been running on the site for more than two and a half years. Igor publishes the source code as a class BSD license. In the case of high concurrent connections, Nginx is a good alternative to the Apache server. Nginx can also be used as a 7-layer load balancing server. According to the test results, Nginx 0.6.31 + PHP 5.2.6 (FastCGI) can withstand more than 30,000 concurrent connections, which is equivalent to 10 times that of Apache in the same environment. However, many people will get 500 errors when using Nginx. According to my usage, a large part of the reason is because the file open handle is too small.

Under linux Use this command to increase the file handle opened by the process. Ulimit -SHn 51200 The default is only 1000. When the number of links is small, you can't see it. This method can effectively prevent 500 errors from occurring. When I visit the website today, I occasionally encounter the error message page of 500 Internal Server Error. I checked the relevant information and found that the access is too large, and the system kernel process is limited.

The answer is as follows:

$ ulimit -n 11095

The program limit can only open 11095 files. The ulimit command is to set the number of file descriptors that a current user can have. It seems that there are too many concurrent concurrency. Need to adjust the number of concurrent settings of nginx.conf, (My configuration host memory 2G, CPU is 2.8G,)

vi /etc/nginx/nginx.conf events { worker_connections 1024; }

Adjust to

events { worker_connections 10240; }

The above problem will still occur, using [root@qimutian nginx]# cat /proc/sys/fs/file-max 8192 The maximum number of open files in the file system [root@qimutian nginx]# ulimit -n 1024 Program limit can only open 1024 files Use [root@qimutian nginx]# ulimit -n 8192 to adjust or permanently adjust the number of open files in the startup file Add at the end of /etc/rc.d/rc.local (in /etc/sysctl.conf Add fs.file-max=8192) ulimit -n 8192 Adjust the number of CentOS5 file openes Use ulimit -a to find that OPEN FILES can't exceed 1024 by default. Yesterday's stress test showed 500 errors. Please check nginx for details. 500 Internal Server Error Look up in the morning and find that it was adjusted as follows. Method 1 (permanent adjustment)

vi /etc/security/limits.conf

Add at the end of the file: Br>

* soft nofile 8192 * hard nofile 20480

At the same time vi /etc/sysctl.conf add fs.file-max=8192 to restart, the number used in ulimit -n is already 8192

Method 2 (temporary)

Enter ulimit -n 8192 directly in the terminal. Press Enter to ok.

500 Internal Server Error error added: 1. Hard disk space is full

Use df -k to see if the hard disk space is full. Clearing the hard disk space will solve the 500 error. If nginx has access log enabled, it is best to close the access log if it is not needed. The access log takes up a lot of hard disk space. 2, nginx configuration file error

This is not a syntax error, nginx if the configuration file has a syntax error, it will prompt when starting. When rewrite is configured, some rules will be mishandled with 500 errors. Please check your rewrite rules carefully. If some variables in the configuration file are not set properly, there will be a 500 error, such as referencing a variable with no value. 3. If none of the above problems exist, there may be too many concurrent concurrency. You need to adjust the number of concurrent settings of nginx.conf.

The solution is:

1 Open /etc/Security/limits.conf file, plus two sentences

* soft nofile 65535 * hard nofile 65535

2 Open /etc/nginx/nginx.conf Add a line below worker_processes

worker_rlimit_nofile 65535;

3 Restart nginx, reload settings

kill -9 `ps -ef

Copyright © Windows knowledge All Rights Reserved