잠시만 기다려 주세요

     '입만 나불거리고 행동하지 않는 민주당을 규탄한다.'
전체검색 :  
이번주 로또 및 연금번호 발생!!   |  HOME   |  여기는?   |  바다물때표   |  알림 (26)  |  여러가지 팁 (1125)  |  추천 및 재미 (166)  |  자료실 (25)  |  
시사, 이슈, 칼럼, 평론, 비평 (1040)  |  끄적거림 (154)  |  문예 창작 (734)  |  바람 따라 (75)  |  시나리오 (760)  |  드라마 대본 (248)  |  
살인!


    리눅스 서버

리눅스 서버 - 502 bad gateway using Nginx
이 름 : 바다아이   |   조회수 : 13598         짧은 주소 : 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:

  1. Nginx running as proxy for Apache web server.
  2. Nginx running with PHP-FPM daemon.
  3. Nginx running with other services as gateway.
  4. 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:

  1. 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.
  2. 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.
  3. 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:

http {
...
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
...
}

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 를 사용하기를 권합니다.
그리고 저 위에 설정 문제들이라면 이것저것 만져보면서 해결이 되겠지만
간헐적이거나 서버 부하 문제라면 이 때는 무조건 램 증설이 답입니다. -.-;

 

| |





      5 page / 6 page
번 호 카테고리 제 목 이름 조회수
43 리눅스 서버 OpenVZ vs KVM, Xen , 바다아이 13216
42 리눅스 서버 roundcubemail 4 바다아이 12765
41 리눅스 서버 [Imap] Qmail + Vpopmail + Dovecot 바다아이 17004
40 리눅스 서버 Roundcubemail 0.3.1 , 바다아이 16180
39 리눅스 서버 qmail + vpopmail 바다아이 12789
38 리눅스 서버 PHP 7.0 on CentOS/RHEL 6.7 and 7.1 via Yum 바다아이 22366
37 리눅스 서버 CentOS 7 firewalld iptables 바다아이 13566
36 리눅스 서버 , webalizer , 바다아이 12972
35 리눅스 서버 iptables ssh , ssh 바다아이 12783
34 리눅스 서버 ssh - fail2ban, SSH Brute-force attack 바다아이 16340
33 리눅스 서버 NGINX php ... 바다아이 62097
32 리눅스 서버 CentOS 7 | firewall-cmd 바다아이 13256
31 리눅스 서버 SSH (Secure Shell) 바다아이 16477
30 리눅스 서버 proftp , , proftpd.conf 바다아이 16172
29 리눅스 서버 centos 7 iptables firewall-cmd 바다아이 14089
28 리눅스 서버 바다아이 13150
27 리눅스 서버 netstat, nmap 바다아이 13632
26 리눅스 서버 Apache IP , 바다아이 12455
25 리눅스 서버 , 바다아이 13287
24 리눅스 서버 php php.ini , 바다아이 16147
23 리눅스 서버 mysql, mariadb (UTF8) .. ??? 바다아이 14838
22 리눅스 서버 , , , 바다아이 13462
21 리눅스 서버 top 바다아이 16272
20 리눅스 서버 [subversion] ubuntu subversion 바다아이 15945
19 리눅스 서버 2 mod_cband , 바다아이 17442
18 리눅스 서버 바다아이 13399
17 리눅스 서버 Apache event MPM, Prefork MPM, Worker MPM 바다아이 16633
16 리눅스 서버 Virtual Hosting 바다아이 15986
15 리눅스 서버 fedora selinux , ... , , ftp, mysql ... 바다아이 14054
14 리눅스 서버 ssh rsync 바다아이 13265
| |









Copyright ⓒ 2001.12. bada-ie.com. All rights reserved.
이 사이트는 리눅스에서 chrome 기준으로 작성되었습니다. 기타 브라우저에서는 다르게 보일 수 있습니다.
[ Debian + GoLang + PostgreSQL + Mariadb + PgBouncer + ProxySQL]
서버위치 : San Jose Datacenter  실행시간 : 0.06012
to webmaster... gogo sea. gogo sea.