One-click LNMP installation environment 502 Bad Gateway

Source: Internet
Author: User
Tags fpm install php mysql version socket ssh wordpress version nginx reverse proxy

The LNMP one-click installation package is set up in the environment, but I found that the 502 Bad Gateway error occurred in some pages during my wordpress background. Let's look at the solution below.

My PHP version is 5.2.17

Mysql version 5.1.60

WordPress 3.8.3

After reading the php-fpm log, it is basically similar to the following errors:

The code is as follows: Copy code
May 13 19:35:21. 668482 [WARNING] fpm_stdio_child_said (), line 167: child 12854 (pool default) said into stderr: "[Tue May 13 19:35:16 2014"
May 13 19:35:21. 680238 [WARNING] fpm_stdio_child_said (), line 167: child 12854 (pool default) said into stderr: "] [notice] EACCELERATOR (12854): PHP crashed on opline 469 of curl_exec () at/*/wp-des/class-http.php: 1249 ", pipe is closed
May 13 19:35:21. 680267 [WARNING] fpm_stdio_child_said (), line 167: child 12854 (pool default) said into stderr: "", pipe is closed
May 13 19:35:21. 680285 [NOTICE] fpm_got_signal (), line 48: received SIGCHLD
May 13 19:35:21. 680317 [WARNING] fpm_children_bury (), line 215: child 12854 (pool default) exited on signal 11 SIGSEGV after 2056.281254 seconds from start
May 13 19:35:21. 680742 [NOTICE] fpm_children_make (), line 352: child 20797 (pool default) started

After querying the solution on the Internet, the modification has basically no effect, and the error persists.

Try the first method: change unix socket to TCP/IP
Modify

The code is as follows: Copy code

/Usr/local/php/etc/php-fpm.cnf
Set

<Value name = "" listen_address ">/tmp/nginx. socket </value>
Inside

/Tmp/nginx. socket
Modify

127.0.0.1: 9000
At the same time, in the configuration of/usr/local/nginx/conf/nginx. conf and/usr/local/nginx/conf/vhost/,

Fastcgi_pass unix:/tmp/php-cgi.sock;
Modify

Fastcgi_pass 127.0.0.1: 9000;

Then restart LNMP.

This method solves the 502 error in some backend of wodpress, but the 502 Bad Gateway error still occurs on the update page and plug-in page.

 

So I tried the second method to modify libsqlite3.so. 0.8.6.
The 32-bit modification is as follows:

The code is as follows: Copy code

Mv/usr/lib/libsqlite3.so. 0.8.6/usr/lib/libsqlite3.so. 0.8.6.bak
The 64-bit modification is as follows:

Mv/usr/lib64/libsqlite3.so. 0.8.6/usr/lib64/libsqlite3.so. 0.8.6.bak

After the modification, log on to wordpress and open the update page and plug-in page. The error 502 Bad Gateway does not appear.

Now the problem is solved.

But now it's strange to me that the second method is really amazing? How can I come up with a solution to this problem? How did I find it?

Hope you can give me some advice.

 

The military brother of LNMP maker said,

Only in centos 6 php 5.2.17 + wordpress 3.8.1 will 502

No problem with wordpress beta

Php 5.3 is okay

But in fact, my current wordpress version has the same problem, so it should be the cause of PHP5.2!

Remind friends who use LNMP one-click installation. If you want to avoid the 502 Bad Gateway error, we recommend that you install PHP 5.3 !!

The following are some solutions that are not caused by the php version.

I. fastcgi buffer settings are too small
If an error occurs, first find the nginx log file in the/var/log/nginx Directory. The following error is found in the log.

13:33:47 [error] 15421 #0: * 16 upstream sent too big header while reading response header from upstream

After checking the information, the problem was caused by a bug in the nginx buffer zone. The page consumption on our website may be too large.

I found a solution on the Internet, and found a method for adding a buffer on a foreign website, which completely solved the problem of Nginx 502 Bad Gateway. The method is as follows:

The code is as follows: Copy code
Http {
...
Fastcgi_buffers 8 16 k;
Fastcgi_buffer_size 32 k;
...
}

Increase the preceding two configuration items based on your website.

II. The proxy buffer settings are too small
If you are using nginx reverse proxy, if the header is too large, it exceeds the default 1 k, the above upstream sent too big header will be triggered (to put it bluntly, nginx will process external requests to the backend. If the header returned by the backend is too large, nginx will cause 502 if it cannot process it.

The code is as follows: Copy code
Server {
Listen 80;
Server_name *. lxy. me;
 
Location /{
 
############## Add the three rows
Proxy_buffer_size 64 k;
Proxy_buffers 32 32 k;
Proxy_busy_buffers_size 128 k;
############## Add the three rows
Proxy_set_header Host $ host;
Proxy_set_header X-Real-IP $ remote_addr;
Proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;
............
}

3. The default number of php-cgi processes is too small.
502 problems occur during installation and use. Generally, the default php-cgi process is five, which may be caused by insufficient phpcgi processes, you need to modify/usr/local/php/etc/php-fpm.conf to add the max_children value as appropriate. It is also possible that the max_requests value is insufficient. It must be noted that this configuration item occupies a large amount of memory. Please set it according to the server configuration. Otherwise, it may have a negative effect.

IV. php execution timeout
Php execution time-out. Modify/usr/local/php/etc/php. ini and change max_execution_time to 300.

5. nginx wait time timeout
The execution time of some PHP programs exceeds the Nginx waiting time. You can add the FastCGI timeout time in the nginx. conf configuration file as appropriate.


Http {
Fastcgi_connect_timeout 300;
Fastcgi_send_timeout 300;
Fastcgi_read_timeout 300;
......
} Solved the problem,

Method 3


First, check the ulimit-n value. Run the following command on SSH:

The code is as follows: Copy code
# Ulimit-n

Return value: 65535
1. Open the file handle of the server.

SSH command: # vi/etc/security/limits. conf. Add the following content at the end:

The code is as follows: Copy code
* Soft nofile 65535
* Hard nofile 65535

2. Increase the number of opened processes in nginx

The code is as follows: Copy code
# Vi/usr/local/nginx/conf/nginx. conf

View worker_rlimit_nofile 51200;
3. Modify the php-fpm.conf configuration file

The ulimit-n value was determined to be 65535, and the option rlimit_files in/usr/local/php/etc/php-fpm.conf must be consistent with this value.

The code is as follows: Copy code
<Value name = "rlimit_files"> 65535 </value>
<Value name = "maid"> 10240 </value>

4. Modify sysctl. conf.

The code is as follows: Copy code

# Vi/etc/sysctl. conf

Add at the bottom

The code is as follows: Copy code
Fs. file-max = 65535

At this point, restart/root/lnmp restart takes effect. Check if there is any similar error message!

Ps. To reduce the size of the php-fpm.log file, you can change the Log level in the/usr/local/php/etc/php-fpm.conf from notice to ERROR, which can reduce the Log generation speed!

The code is as follows: Copy code

Log level
<Value name = "log_level"> Error </value>

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.