Lnmpa encountered 504 Gateway time-out error solution

Source: Internet
Author: User

Intermediary transaction http://www.aliyun.com/zixun/aggregation/6858.html ">seo diagnose Taobao guest cloud host technology Hall

Nginx is characterized by the processing of static is very strong, Apache is characterized by dynamic processing is very stable, the two combination is Lnmpa,nginx processing front-end, Apache processing back-end, so that processing static will be very fast, processing dynamic will be very stable. When I thought the installation was finished, but when the update site appeared 504 Gateway time-out; At first it was thought it was accidental, and after many attempts it still appeared, and therefore decided to find a solution.

LNMP Face 504 Gateway time-out

Because the 504 Gateway time-out is Nginx's exclusive error, so at first I thought it was nginx configuration error, find the online tutorials, find the appropriate solution, the following simple talk about LNMP face this situation solution. Nginx This error occurs because the number of php-cgi processes is too limited, and in the face of such operations as updating the Web site, there is likely to be a lack of process and timeout, so modify two files that involve processing time.

The first is the nginx.conf file, this file in/nginx/conf/nginx.conf, opened, mainly modify the previous several times, the proposed modification for more than 120 seconds. As for what tools to modify, recommend online command line edit, or download it with WINSCP, use Dreamweaver to modify.

Fastcgi_connect_timeout 300s;

Fastcgi_send_timeout 300s;

Fastcgi_read_timeout 300s;

Fastcgi_buffer_size 128k;

Fastcgi_buffers 8 128k #8 128

Fastcgi_busy_buffers_size 256k;

Fastcgi_temp_file_write_size 256k;

Second, modify the php-fpm.conf file, which is in the/php-5.2.17/etc/ Php-fpm.conf, different one-click installation package location is different, anyway look for PHP installation after the file, etc folder can be edited online or downloaded down with Dreamweaver edit.

After entering the file search "Max_children" This is the number of php-cgi processes, a process accounted for 20m~30m memory, according to their own VPS or cloud host memory, like 512M memory, recommended set to 18; Timeout ", this is the timeout time, if the PHP program to operate for a long time, then set a larger time will be better, like set to 120 seconds, the unit default is seconds, or write 120 can also.

Lnmpa Encounters 504 Gateway time-out

When I follow the Nginx solution settings, soon set a successful, but still will appear 504 Gateway time-out, when I directly switch to LNMP combination, found no longer encountered 504 Gateway time-out error, which indicates that the setting has been in effect; Why is there such a mistake?

After a lot of data search, finally found that this is nginx and Apache communication time setup problem, when the user issued a PHP script execution request, Nginx will not execute PHP, will leave the problem to the backstage Apache,nginx will wait for some time, Apache can be in the waiting time processing PHP script request, if not finished, Nginx has not received the data request and return 504 Gateway time-out error, the actual situation is Apache will still be in the background processing PHP script, only the foreground returned error.

The solution is to modify nginx and Apche communication time, specifically configuration proxy.conf, this file under the/nginx/conf/, the name may be changed, like some installation package is laproxy.conf, anyway, **proxy.conf file.

Proxy_connect_timeout 60;

Proxy_send_timeout 600;

Proxy_read_timeout 90;

Proxy_buffer_size 128k;

Proxy_buffers 8 128k;

Proxy_busy_buffers_size 256k;

Proxy_temp_file_write_size 100m;

The first is the connection time, front-end connection back-end time, 60s can be, the second is to send time, allow the back end of the time to return data, 90s can be, the third time is read and write time, this is the front-end waiting for the processing time, which is leading to 504 Gateway time-out root cause, This error, indicating that this value is too small, recommended not less than 600s, the server is worse, then set longer to ensure that the processing is complete.

When I set up this file, restart Nginx and Apache, and update the article again, no such error has been encountered, indicating that the reason for the error is not nginx, but the communication time between the front and back end is too short. In addition, Nginx will also have 502 errors, in fact, the principle is similar to the same set of files above, the Lnmpa combination is still set back and forth the communication time. This article by 121 good Information (http://www.121h.com/) completed, reproduced share please specify, thank you for your cooperation, may wish to keep the link!

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.