잠시만 기다려 주세요

     '대한민국이 더이상 발전하지 못하는 것은 부패한 언론들의 쓰레기짓 때문이다.'
전체검색 :  
이번주 로또 및 연금번호 발생!!   |  HOME   |  여기는?   |  바다물때표   |  알림 (19)  |  여러가지 팁 (1095)  |  추천 및 재미 (163)  |  자료실 (28)  |  
시사, 이슈, 칼럼, 평론, 비평 (799)  |  끄적거림 (142)  |  문예 창작 (719)  |  바람 따라 (75)  |  시나리오 (760)  |  드라마 대본 (248)  |  
살인!


    리눅스 서버

리눅스 서버 - 502 bad gateway using Nginx
이 름 : 바다아이   |   조회수 : 11249         짧은 주소 : 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 를 사용하기를 권합니다.
그리고 저 위에 설정 문제들이라면 이것저것 만져보면서 해결이 되겠지만
간헐적이거나 서버 부하 문제라면 이 때는 무조건 램 증설이 답입니다. -.-;

 

| |





      1 page / 6 page
번 호 카테고리 제 목 이름 조회수
155 리눅스 서버 apt ... ... apt 바다아이 306
154 리눅스 서버 , smartctl, hdd ssd 바다아이 460
153 리눅스 서버 , .... arch kernel compile.... 바다아이 448
152 리눅스 서버 [Vim, Vi] 바다아이 428
151 리눅스 서버 ... 바다아이 511
150 리눅스 서버 vps root .. 바다아이 462
149 리눅스 서버 Ubuntu 24.04 LTS - SSH Port , ssh 바다아이 493
148 리눅스 서버 samba ... , ... 바다아이 1388
147 리눅스 서버 postfix main.cf ... 바다아이 5036
146 리눅스 서버 /etc/crontab ... 바다아이 3359
145 리눅스 서버 - MEMTEST, , 바다아이 5042
144 리눅스 서버 top , top 바다아이 5680
143 리눅스 서버 , systemd-networkd, archlinux network setting 바다아이 7046
142 리눅스 서버 mirror .. ... 바다아이 7306
141 리눅스 서버 [Ubuntu] (swapfile) , ... 바다아이 7342
140 리눅스 서버 ufw , iptables 바다아이 8293
139 리눅스 서버 ... grub . submenu, grub-mkconfig, grub 바다아이 6840
138 리눅스 서버 CentOS 7 Upgrade Kernel, centos 바다아이 9220
137 리눅스 서버 , dd , 바다아이 7170
136 리눅스 서버 ... ntp .. ... 바다아이 7930
135 리눅스 서버 archlinux netstat , netstat ... 바다아이 7543
134 리눅스 서버 ps , ps option 바다아이 7366
133 리눅스 서버 , swap , ... swap . 바다아이 7532
132 리눅스 서버 crontab , .... 바다아이 7540
131 리눅스 서버 ssh , ssh 바다아이 8785
130 리눅스 서버 SSH SSH , ssh-keygen rsa 바다아이 8295
129 리눅스 서버 , date : () , () , 바다아이 8550
128 리눅스 서버 aws lightsail, ssh .. .pem 바다아이 13567
127 리눅스 서버 , ubuntu generic kernel 바다아이 8937
126 리눅스 서버 .. apt ... 바다아이 8810
| |









Copyright ⓒ 2001.12. bada-ie.com. All rights reserved.
이 사이트는 리눅스에서 firefox 기준으로 작성되었습니다. 기타 브라우저에서는 다르게 보일 수 있습니다.
[ Ubuntu + GoLang + PostgreSQL + Mariadb ]
서버위치 : 오라클 클라우드 춘천  실행시간 : 0.12217
to webmaster... gogo sea. gogo sea.