nginx 502 잘못된 게이트웨이
spawn fcgi를 사용하여 php5-cgi를 생성 할 때 nginx와 함께 502 Bad Gateway를 얻습니다.
이것을 사용하여 rc.local의 다음 줄을 사용하여 서버 시작의 인스턴스를 확장합니다.
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -g www-data -f /usr/bin/php5-cgi -P /var/run/fastcgi-php.pid
아마도 spawn-fcgi / php5-cgi가 죽고 PHP를 구문 분석하기 위해 더 이상 청취하는 것이 없기 때문에 오류가 발생합니다.
나는 어디서나 볼 수있는 로그를 얻지 못하고 아이디어가 부족합니다 (nginx 로이 설정이 처음)
내 실행 localhost
하고 페이지에 502 bad gateway
메시지가 표시되었습니다. 이것은 나를 도왔습니다.
- 편집하다
/etc/php5/fpm/pool.d/www.conf
- 변경
listen = /var/run/php5-fpm.sock
에listen = 127.0.0.1:9000
- nginx.conf에 위치가 올바르게 설정되어 있는지 확인하십시오 .
- 운영
sudo service php5-fpm restart
아마 도움이 될 것입니다.
출처 : http://wildlyinaccurate.com/solving-502-bad-gateway-with-nginx-php-fpm
nginx가 php5-cgi로 전달할 수 없기 때문에 502 오류가 나타납니다. tcp가 아닌 유닉스 소켓을 사용하도록 php5-cgi를 재구성 할 수 있습니다 .. 그런 다음 tcp 대신 소켓을 가리 키도록 서버 구성을 조정할 수 있습니다.
ps auxww | grep php5-cgi #-- is the process running?
netstat -an | grep 9000 # is the port open?
로 이동 /etc/php5/fpm/pool.d/www.conf
하여 소켓을 사용 중이거나이 행이 주석 처리되지 않은 경우
listen = /var/run/php5-fpm.sock
다른 값도 설정하십시오.
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
php-fpm 및 nginx를 다시 시작하는 것을 잊지 마십시오. 동일한 nginx 소유자 및 그룹 이름을 사용하고 있는지 확인하십시오.
소켓 또는 TCP를 통해 통신하려면 PHP-FPM 및 Nginx의 설정을 일치시켜야합니다.
따라서 /etc/php5/fpm/pool.d/www.conf
다음 줄로 이동하십시오.
listen = /var/run/php5-fpm.sock
그런 다음 /etc/nginx/nginx.conf
이것을 찾으십시오 :
upstream php {
server unix:/var/run/php5-fpm.socket;
}
해당 값과 일치하면 모든 설정이 완료되어야합니다.
Linux 서버를 실행하는 경우 IPTABLES 구성이 올바른지 확인하십시오.
을 실행 sudo iptables -L -n
하면 열린 포트 목록이 표시됩니다. fcgi 스크립트를 제공하는 포트를 여는 Iptables 규칙이없는 경우 502 오류가 발생합니다. 올바른 포트를 여는 Iptables 규칙 은 모든 패킷을 범주 적으로 거부하는 규칙 (즉, 형식 또는 유사한 규칙) 앞에 나열되어야합니다."REJECT ALL -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-port-unreachable
내 구성에서 포트를 제대로 열려면 다음 명령을 실행해야했습니다 (내 fcgi 서버가 포트 4567에서 실행 중이라고 가정).
sudo iptables -I INPUT 1 -p tcp --dport 4567 -j ACCEPT
경고 : 이렇게하면 전 세계에 포트 4567이 열립니다.
따라서 다음과 같이하는 것이 더 나을 수 있습니다.
sudo iptables-save >> backup.iptables
sudo iptables -D INPUT 1 #Delete the previously entered rule
sudo iptables -I INPUT 1 -p tcp --dport 8080 -s localhost -j ACCEPT # Add new rule
이렇게하면 502 오류가 제거되었습니다.
변화
fastcgi_pass unix:/var/run/php-fpm.sock;
...에
fastcgi_pass unix:/var/run/php5-fpm.sock;
내가했을 때 sudo /etc/init.d/php-fpm start
다음과 같은 오류가 발생했습니다.
Starting php-fpm: [28-Mar-2013 16:18:16] ERROR: [pool www] cannot get uid for user 'apache'
I guess /etc/php-fpm.d/www.conf
needs to know the user that the webserver is running as and assumes it's apache when, for nginx, it's actually nginx, and needs to be changed.
You can make nginx ignore client aborts using:
location / {
proxy_ignore_client_abort on;
}
I had the same problem while setting up an Ubuntu server. Turns out I was having the problem due to incorrect permissions on socket file.
If you are having the problem due to a permission problem, you can uncomment the following lines from: /etc/php5/fpm/pool.d/www.conf
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
Alternatively, although I wouldn't recommend, you can give read and write permissions to all groups by using the following command.
sudo chmod go+rw /var/run/php5-fpm.sock
Try disabling the xcache or apc modules. Seems to cause a problem with some versions are saving objects to a session variable.
Hope this tip will save someone else's life. In my case the problem was that I ran out of memory, but only slightly, was hard to think about it. Wasted 3hrs on that. I recommend running:
sudo htop
or
sudo free -m
...along with running problematic requests on the server to see if your memory doesn't run out. And if it does like in my case, you need to create a swap file (unless you already have one).
I have followed this tutorial to create swap file on Ubuntu Server 14.04 and it worked just fine: http://www.cyberciti.biz/faq/ubuntu-linux-create-add-swap-file/
If you're on Ubuntu, and all of the above has failed you, AppArmor is most likely to blame.
Here is a good guide how to fix it: https://www.digitalocean.com/community/tutorials/how-to-create-an-apparmor-profile-for-nginx-on-ubuntu-14-04
Long story short:
vi /etc/apparmor.d/nginx
Or
sudo aa-complain nginx
sudo service nginx restart
See everything working nicely... then
sudo aa-logprof
I still had problems with Nginx not being able to read error.log, even though it had all the permissions possible, including in Apparomor. I'm guessing it's got something to do with the order of the entries, or some interaction with Passenger or PHP-Fpm... I've run out of time to troubleshoot this and have gone back to Apache for now. (Apache performs much better too FYI.)
AppArmor just lets Nginx do whatever it wants if you just remove the profile:
rm /etc/apparmor.d/nginx
service apparmor reload
Shockingly, but hardly surprising, a lot of posts on fixing Nginx errors resorts to completely disabling SELinux or removing AppArmor. That's a bad idea because you lose protection from a whole lot of software. Just removing the Nginx profile is a better way to troubleshoot your config files. Once you know that the problem isn't in your Nginx config files, you can take the time to create a proper AppArmor profile.
Without an AppArmor profile, especially if you run something like Passenger too, I give your server about a month to get backdoored.
Similar setup here and looks like it was just a bug in my code. At the start of my app I looked for the offending URL and this worked: echo '<html>test</html>'; exit();
In my case, turns out the problem was an uninitialized variable that only failed under peculiar circumstances.
참고URL : https://stackoverflow.com/questions/4252368/nginx-502-bad-gateway
'IT TIP' 카테고리의 다른 글
Java의 열거 형에 함수를 추가 할 수 있습니까? (0) | 2020.12.04 |
---|---|
상속을 사용하는 이유는 무엇입니까? (0) | 2020.12.04 |
함수를 호출 한 요소의 ID 가져 오기 (0) | 2020.12.04 |
클러스터를 사용하여 Socket.IO를 여러 Node.js 프로세스로 확장 (0) | 2020.12.04 |
Visual Studio 프로젝트의 ipch 파일 (0) | 2020.12.04 |