Experience: nginx php 502 bad gateway solution

Source: Internet
Author: User
Tags fpm ini php session connection reset phpmyadmin server memory

The following error occurs when you access phpMyAdmin.

PhpMyAdmin-Error

Cannot start session without errors, please check errors given in your PHP and/or webserver log file and configure your PHP installation properly.The first time you open the prompt, refresh the prompt:

502 bad gateway

View nginx error log:

[Error] recv () failed (104: Connection reset by peer) while reading response header from upstream, client:, server:, request: "GET/HTTP/1.1", upstream: "fastcgi: // 127.0.0.1: 9000", host: "mysql.veryi.com"

View the php session. save_path settings. The default value is/var/lib/php/session.Users who modify the nginx process in this directory have read and write permissions.Solve the problem.

Other possibilities:

When the execution time of some PHP programs exceeds the Nginx waiting time, you can increase the FastCGI timeout time in the nginx. conf configuration file, for example:

The code is as follows: Copy code
Http
{
Fastcgi_connect_timeout 300;
Fastcgi_send_timeout 300;
Fastcgi_read_timeout 300;
}

If memory_limit is set to a lower value in php. ini, an error occurs. You can increase memory_limit of php. ini to 64 MB.

Other causes that may cause 502 bad gateway errors

Insufficient. php-fpm process count

Use netstat-napo | grep "php-fpm" | wc-l to check the number of fastcgi processes. If the number is close to the upper limit configured in conf, you need to increase the number of processes.

However, you cannot increase the number of php-fpm sub-processes to 100 or more based on the server memory.


2. Increase the number of files opened in the Linux kernel.

You can use these commands (must be a root account)

Echo 'ulimit-HSn 65536 '>/etc/profile

Echo 'ulimit-HSn 65536 '>/etc/rc. local

Source/etc/profile

3. The script execution time has timed out.

If the script does not return after a long wait for some reason, the new request cannot be processed, you can adjust the following configurations as appropriate.

Nginx. conf mainly includes the following:

Fastcgi_connect_timeout 300;
Fastcgi_send_timeout 300;
Fastcgi_read_timeout 300;

If the php-fpm.conf is as follows

Request_terminate_timeout = 10 s

4. Relatively small cache settings

Modify or add configuration to nginx. conf

Proxy_buffer_size 64 k;
Proxy_buffers 512 k;
Proxy_busy_buffers_size 128 k;

5. recv () failed (104: Connection reset by peer) while reading response header from upstream

Possible cause: network packet loss in the IDC or access to this domain name is prohibited by the hardware firewall in the IDC

But the most important thing is to set the timeout in the program. Do not use the request_terminate_timeout of php-fpm,

It is best to set it to request_terminate_timeout = 0;

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.