이 름 : 바다아이
|
조회수 : 10102
짧은 주소 : https://www.bada-ie.com/su/?251591803327
Many times we can browse the web and find a 502 bad gateway error at Nginx. There are a few reasons why you will find this message in your webserver log, and here we will teach you how to fix it.
When you will find 502 bad gateway error:
Nginx running as proxy for Apache web server.
Nginx running with PHP-FPM daemon.
Nginx running with other services as gateway.
Bad buffering/timeout configuration.
Before getting deep into all of this options, you must understand what does the error message means. So, the error it’s a 502 number and it’s happening at the gateway. What the hell is a gateway? In simple words, a gateway, is like an access point, a bridge that communicate one service with another, in this case the gateway can be a service/application that is working and recieving requests from Nginx web server.
Now, let’s explore each one of this reasons to understand the 502 bad gateway message:
Nginx as Proxy for Apache: in this case, the gateway is Apache. When you use Nginx as proxy for Apache, if apache dies or it’s not well configured, it can cause this 502 error. How to fix it? Most of the times, restarting apache web server will get rid of this, but you must check the log files to know why exactly this was caused.
Nginx with PHP-FPM: same as Apache example, let’s imagine your php daemon stop working, or get’s overloaded by requests, it will not work properly and the all the php requests from nginx would not be served, so, an error will appear. How to fix it? Restart php-fpm daemon and check the logs.
Nginx with other services/apps: try restarting the other service behind nginx and explore the logs to find the reason why it happened.
Other quick solutions:
1) Increase buffer and timeouts inside http block:
2) Ensure your php-fpm service is listening according to what you’ve configured in nginx, it can be either this two options:
Edit www.conf file (in CentOS it is located at /etc/php-fpm.d/www.conf and try with one of this two options:
listen = /var/run/php5-fpm.sock
or
listen = 127.0.0.1:9000
After that, just restart the php-fpm service.
3) Disable APC Cache if used, instead try Xcache, apc can cause this kind of issues under particular enviroments causing segmentation faults.
4) I recently found another cause of 502 bad gateway error, check it out here: php5-fpm.sock failed (13: Permission denied) error
p.s
원인을 보면... 다양한데... 대부분 서버 부하입니다. 타임아웃 늘려주고 버퍼 늘려주고....
어느 정도 해결이 될 겁니다. 근데 곳곳에서 또 튀어 나오죠 ^^;
502 에러의 대부분은 아마 서버 부하로 인해 하드웨어적으로 램이 부족하여 일어나는 현상입니다.
그걸 요리조리 짜 맞추면서 분배를 잘 해야 하는데 쉽지 않습니다.
암튼 nginx 는 서버 부하 걸리면 곳곳에 숨어서 502 에러를 뿜어냅니다.
임시적으로 타임아웃 값과 버퍼를 늘려 기다리게 할 수는 있겠지만 근본적인 해결책은 아닙니다.
결론적으로 접속자가 많은 곳은 무조건 메모리를 빵빵하게 해라.. 그게 정답입니다..
참고로 최소 사양으로는 1G 이상 되는 곳에 nginx 를 사용하기를 권합니다.
그리고 저 위에 설정 문제들이라면 이것저것 만져보면서 해결이 되겠지만
간헐적이거나 서버 부하 문제라면 이 때는 무조건 램 증설이 답입니다. -.-;
|
|
번 호
카테고리
제 목
이름
조회수
Copyright ⓒ 2001.12. bada-ie.com. All rights reserved.
이 사이트는 리눅스에서 firefox 기준으로 작성되었습니다. 기타 브라우저에서는 다르게 보일 수 있습니다.
[ Ubuntu + GoLang + PostgreSQL + Mariadb ]
서버위치 : 오라클 클라우드 춘천 실행시간 : 0.08114 초 to webmaster... gogo sea. gogo sea.