Nginx Tip: Internal Server Error Resolution

Source: Internet
Author: User
Tags file system

This article to give you a lot of information on the cause of Nginx Internal Server error errors in the summary and solution analysis of the need to know friends can refer to

More and more sites are starting to use Nginx, ("Engine X") is a high-performance HTTP and reverse proxy server, but also a IMAP/POP3/SMTP proxy server. Nginx was developed by Igor Sysoev, the second rambler.ru site for Russian traffic, which has run over 2.5 at the site. Igor releases the source code in the form of a BSD-like license.

In the case of high concurrent connections, Nginx is a good substitute for Apache servers. Nginx can also be used as a 7-tier 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 times the same environment Apache.

But many people use Nginx when there will be 500 errors, according to my use of the situation, a large part of the reason is because the file open handle too small related.

Use this command under Linux to increase the file handle opened by the process.

Ulimit-shn 51200

The default is only 1000 when the number of links is small to see, use this approach can effectively prevent 500 errors appear.

When you visit the website today, you will occasionally encounter the error prompt page of the Internal Server error.

The relevant information is considered to be too large, the system kernel process is limited to appear.

The answer is as follows:

$ ulimit-n

11095

The program limit opens only 11,095 files, and the Ulimit command sets the number of file descriptors a process can hold for the current user.

It seems that there are too many analog concurrency, you need to adjust the number of concurrent settings for nginx.conf (my configuration host's memory 2g,cpu to 2.8G)

Vi/etc/nginx/nginx.conf

Events {

Worker_connections 1024;

}

Adjusted to

Events {

Worker_connections 10240;

}

Or there will be the above problem, using

[Root@qimutian nginx]# Cat/proc/sys/fs/file-max

8192

File system maximum number of open files

[Root@qimutian nginx]# Ulimit-n

1024

Program restrictions open only 1024 files

Use [Root@qimutian nginx]# ulimit-n 8192 to adjust

or permanently adjust the number of open files to add 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, found that open files can not default to more than 1024, yesterday in the stress test, there are 500 errors, please see

Nginx appears Internal Server Error

Get up and look in the morning and find out that it was adjusted by the following way

Method 1 (permanent adjustment)

Vi/etc/security/limits.conf

At the end of the file, add:

* Soft Nofile 8192

* Hard Nofile 20480

Add vi/etc/sysctl.conf at the end

fs.file-max=8192

Reboot, the number viewed using Ulimit-n is already 8192

Method 2 (Temporary use)

Directly in the terminal input Ulimit-n 8192 Press ENTER on the OK

Internal Server Error Error added:

1, the hard disk space is full

Use Df-k to see if the hard disk space is full. Cleaning up the hard disk space will resolve the 500 error. Nginx If you have access log turned on, it's a good idea to close access log if you don't need it. Access log takes up a lot of hard disk space.

2. nginx Config file error

This is not a syntax error, nginx if the configuration file has a syntax error, it will be prompted when it starts. When configuring rewrite, some rules will be improperly handled 500 errors, please carefully check your rewrite rules. If some of the variables in the configuration file are not set incorrectly, there will also be 500 errors, such as referencing a variable with no value.

3, if the above problem does not exist may be the number of simulated concurrency is too much, need to adjust the number of concurrent settings nginx.conf

The solution is:

1 Open/etc/security/limits.conf file, add two sentences

* Soft Nofile 65535

* Hard Nofile 65535

2 Open/etc/nginx/nginx.conf

Add a row below the worker_processes

Worker_rlimit_nofile 65535;

3 reboot Nginx, reload settings

Kill-9 ' Ps-ef | grep php | Grep-v grep | awk ' {print $} '

/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, look at the Nginx error log, also did not find 500 errors.

4, there may be a database problem in my nginx log php log did not find any problems, and finally found that the database can not be accessed, fixed problem resolution.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.