nginx prompt: 500 Internal Server Error solution
Nginx ("engine x") is a high-performance HTTP and reverse proxy server, as well as an IMAP/POP3/SMTP proxy server. Nginx was developed by Igor Sysoev for Russia's second most visited Rambler.ru site, where it has been running for more than two and a half years. Igor distributes the source code as a BSD-like license. Nginx is a good alternative to the Apache server for high concurrent connections. Nginx can also be used as a Layer 7 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, equivalent to 10 times the number of Apache in the same environment. But many people will get 500 errors when using Nginx, based on my use of the case, a large part of the reason is because the file open handle is too small related. Use this command under linux to increase the file handle opened by the process. ulimit-SHn 51200 default only 1000 when the number of links is small can not be seen, using this method can effectively prevent 500 errors. When I visit the website today, I occasionally encounter a 500 Internal Server Error page. After checking the relevant information, it is believed that the access is too large and the system kernel process is limited. The answer is as follows: $ulimit -n 11095 The program can only open 11095 files. The ulimit command sets the number of file descriptors that a process can have for the current user. It seems that the number of concurrent simulations is too much, we need to adjust the number of concurrent Settings in nginx.conf, (my configuration host has 2G memory and 2.8G CPU).
vi /etc/nginx/nginx.conf
events {
worker_connections 1024;
}
Be adjusted to
events {
worker_connections 10240;
}
The above problems will still occur, use
[root@qimutian nginx]# cat /proc/sys/fs/file-max
8192
Maximum number of files that can be opened on a file system
[root@qimutian nginx]# ulimit -n
1024
The program can only open 1024 files
Use [root@qimutian nginx]# ulimit -n 8192 to adjust it
Or permanently adjust the number of open files at the end of the startup file /etc/rc.d/rc.local (add fs.file-max=8192 at the end of /etc/sysctl.conf)
ulimit -n 8192
Adjust the number of CentOS5 files open
Use ulimit -a, it is found that OPEN FILES cannot exceed 1024 by default, yesterday in the stress test, there were 500 errors, please check for details
500 Internal Server Error occurs in nginx
When I got up in the morning, I found that it was adjusted in the following way
Method 1 (Permanent Adjustment)
vi /etc/security/limits.conf
At the end of the document add:
* soft nofile 8192
* hard nofile 20480
Add to the end of vi /etc/sysctl.conf
fs.file-max=8192
After restarting, the number of views using ulimit -n is already 8192
Method 2 (for temporary use)
Enter ulimit -n 8192 in the terminal and press Enter
500 Internal Server Error Added:
1. The hard disk space is full
Run the df -k command to check whether the hard disk space is full. Cleaning up hard disk space can solve 500 errors. If access log is enabled in nginx, it is best to disable access log when it is not needed. The access log occupies a large amount of disk space.
2. The nginx configuration file is incorrect
nginx does not refer to syntax errors. If the configuration file has syntax errors, it will prompt you at startup. When configuring the rewrite rule, 500 errors may occur if some rules are improperly handled. Please check your rewrite rule carefully. 500 errors can also occur if some variables in the configuration file are incorrectly set, such as referencing a variable with no value.
3. If the above problems do not exist, it may be that the number of concurrent simulations is too much, and you need to adjust the number of concurrent Settings in nginx.conf
The solution is:
1 open the/etc/security/limits file, plus the two sentences
* soft nofile 65535
* hard nofile 65535
2 Open /etc/nginx/nginx.conf
Add a line below worker_processes
3 Restart nginx and reload the Settings
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 100 -u www-data -f /usr/bin/php-cgi
killall -HUP nginx
After the restart, I looked at the nginx error log again, and no 500 errors were found.
4. It may be a database problem. I did not find any problem in the nginx log and php log, and finally found that the database could not be accessed.
Related article
-
nginx routine maintenance commands
This article mainly introduces nginx daily maintenance such as nginx start, restart, close and other common commands, need friends can refer to the next2014-03-03 -
Add an implementation method to configure the Nginx proxy to allow only internal IP access
In this article, Xiaobian gives you an article about adding Nginx proxy configuration to allow only internal IP access to the implementation method of the article, friends in need can learn.2019-10-10 -
The port is occupied when Nginx is enabled. "Address already in use" is displayed
This article mainly introduces the port is occupied when opening Nginx: Address already in use solution, this article through two methods to introduce the Nginx start, stop and restart operation method, need friends can refer to2018-09-09 -
A detailed introduction to reverse proxy caching
This article mainly introduces the detailed introduction of reverse proxy cache related information, I hope that through this article we can master the application of reverse proxy cache use method, need friends can refer to2017-09-09 -
nginx dynamically adds a method for accessing the whitelist
This article mainly introduces nginx dynamic add access to the white list method, Xiaobian feel very good, now share to you, also give you a reference. Let's take a look2017-02-02 -
Nexus uses the nginx proxy to support HTTPS
This article mainly introduces the use of nginx proxy to support HTTPS protocol, the article through the example code is very detailed, for everyone's study or work has a certain reference learning value, need friends can refer to it2020-05-05 -
A detailed analysis of the difference between break and last in Nginx
This article mainly introduces the relevant information about the difference between the break and the last in Nginx. The article introduces it in great detail through the example code, which has certain reference value for your study or work. The friends who need it will study together with the small series below2021-01-01 -
Example implementation of nginx proxy postgresql
This article mainly introduces the implementation of nginx agent postgresql example, the article through the example code introduction is very detailed, for everyone's study or work has a certain reference learning value, the need of friends below with the small series to learn it2023-10-10 -
Summary of keepalive configuration in Nginx
This article introduces the concept and function of Nginx keepalive configuration, describes the basic principle and advantages of keepalive connection, and gives some common configuration examples, which has certain reference value, interested can understand2023-09-09
Latest comments