itsource

PHP-FPM 및 Nginx: 502 불량 게이트웨이

mycopycode 2022. 12. 4. 22:37
반응형

PHP-FPM 및 Nginx: 502 불량 게이트웨이

배열

  • Ubuntu Server 11.10 64비트
  • Amazon AWS, Ec2, 클라우드에서 호스팅
  • t1.micro 인스턴스

다른 글을 쓰기 전에 Nginx 502의 불량 게이트웨이와 Nginx + PHP-FPM 502의 불량 게이트웨이 스레드를 모두 체크했는데, 안타깝게도 이 점에 대해서는 도움이 되지 않았습니다.

으로 보입니다. php-fpm 설정이 nginx "ph-fpm"이 할 수 .502 Bad Gateway에러, 이건 내가 제거할 수 없는 거야.도메인 루트로 이동해도 특정 디렉토리를 지정하지 않고 표시됩니다.

Amazon EC2 웹 서버를 실행하고 있으며 포트 9000, 포트 80 등이 열려 있습니다.

특히 문제는 어떻게 하면 이 끔찍한 오류를 없앨 수 있을까 하는 것입니다. 니면, 은지 or를 얻을 수 ?php5-fpm실제로 일을 할 수 있습니다.

지금까지 시도한 것

「」, 「」의 편집)이 거의 합니다.php-fpm.conf ★★★★★★★★★★★★★★★★★」nginx.conf.

i. php-fpm.conf

다음을 추가했지만 별로 도움이 되지 않았습니다.

;;;;;;;;;;;;;
; Fpm Start ;
;;;;;;;;;;;;;

;pm.start_servers = 20
;pm.min_spare_servers = 5
;pm.max_spare_servers = 35

그 후 설정 파일을 포함하려고 했습니다.

include=/etc/php5/fpm/*.conf

그건 나를 더 힘들게 했어.

풀 구성

;;;;;;;;;;;;;;;;;;;;;
; FPM Configuration ;
;;;;;;;;;;;;;;;;;;;;;

; All relative paths in this configuration file are relative to PHP's install
; prefix (/usr). This prefix can be dynamicaly changed by using the
; '-p' argument from the command line.

; Include one or more files. If glob(3) exists, it is used to include a bunch of
; files from a glob(3) pattern. This directive can be used everywhere in the
; file.
; Relative path can also be used. They will be prefixed by:
;  - the global prefix if it's been set (-p arguement)
;  - /usr otherwise
;include=/etc/php5/fpm/*.conf

;;;;;;;;;;;;;;;;;;
; Global Options ;
;;;;;;;;;;;;;;;;;;

[global]
; Pid file
; Note: the default prefix is /var
; Default Value: none
pid = /var/run/php5-fpm.pid

; Error log file
; Note: the default prefix is /var
; Default Value: log/php-fpm.log
error_log = /var/log/php5-fpm.log

; Log level
; Possible Values: alert, error, warning, notice, debug
; Default Value: notice
log_level = notice

; If this number of child processes exit with SIGSEGV or SIGBUS within the time
; interval set by emergency_restart_interval then FPM will restart. A value
; of '0' means 'Off'.
; Default Value: 0
;emergency_restart_threshold = 0

; Interval of time used by emergency_restart_interval to determine when 
; a graceful restart will be initiated.  This can be useful to work around
; accidental corruptions in an accelerator's shared memory.
; Available Units: s(econds), m(inutes), h(ours), or d(ays)
; Default Unit: seconds
; Default Value: 0
emergency_restart_interval = 0

; Time limit for child processes to wait for a reaction on signals from master.
; Available units: s(econds), m(inutes), h(ours), or d(ays)
; Default Unit: seconds
; Default Value: 0
;process_control_timeout = 0

; Send FPM to background. Set to 'no' to keep FPM in foreground for debugging.
; Default Value: yes
daemonize = no

;;;;;;;;;;;;;
; Fpm Start ;
;;;;;;;;;;;;;

;pm.start_servers = 20
;pm.min_spare_servers = 5
;pm.max_spare_servers = 35

;;;;;;;;;;;;;;;;;;;;
; Pool Definitions ; 
;;;;;;;;;;;;;;;;;;;;

; Multiple pools of child processes may be started with different listening
; ports and different management options.  The name of the pool will be
; used in logs and stats. There is no limitation on the number of pools which
; FPM can handle. Your system will tell you anyway :)

; To configure the pools it is recommended to have one .conf file per
; pool in the following directory:
include=/etc/php5/fpm/pool.d/*.conf

ii. nginx.conf

솔직히 말하면, 이 설정은 제가 방문한 몇 개의 웹사이트의 일부입니다만, 이 502 Bad Gateway 비즈니스 이전에는 서버가 정상적으로 동작하고 있었습니다(PHP가 동작하지 않는 경우).기간).

문제는 주로 무언가가 끔찍하게 잘못되었다는 사실에 있다. 제가 '', '아까', '아까', '아까',service php5-fpm restart무한 루프나 뭐 그런 거에 걸려 있는데,C 그건 내가 생각할 수도 없는 거야.

풀 구성

user www-data;
worker_processes 1;
pid /var/run/nginx.pid;

events {
    worker_connections 64;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush off;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;

    server {
        listen 80;
        server_name ec2-xx-xx-xx-xx.compute-x.amazonaws.com;

        location ~ ^(.+\.php)(.*)$ {
            root   /home/wayvac/public;
            fastcgi_pass   unix:/var/run/php5-fpm.pid;  
            #fastcgi_pass   127.0.0.1:9000; #Un-comment this and comment "fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;" if you are not using php-fpm.
            fastcgi_index  index.php;
            set $document_root2 $document_root;
            if ($document_root2 ~ "^(.*\\\\).*?[\\\\|\/]\.\.\/(.*)$") { set $document_root2 $1$2; }
            if ($document_root2 ~ "^(.*\\\\).*?[\\\\|\/]\.\.\/(.*)$") { set $document_root2 $1$2; }
            if ($document_root2 ~ "^(.*\\\\).*?[\\\\|\/]\.\.\/(.*)$") { set $document_root2 $1$2; }
            if ($document_root2 ~ "^(.*\\\\).*?[\\\\|\/]\.\.\/(.*)$") { set $document_root2 $1$2; }
            if ($document_root2 ~ "^(.*\\\\).*?[\\\\|\/]\.\.\/(.*)$") { set $document_root2 $1$2; }
            fastcgi_split_path_info ^(.+\.php)(.*)$;
            fastcgi_param   SCRIPT_FILENAME $document_root2$fastcgi_script_name;
            fastcgi_param   PATH_INFO   $fastcgi_path_info;
            fastcgi_param   PATH_TRANSLATED $document_root2$fastcgi_path_info;
            include fastcgi_params;
            fastcgi_param  DOCUMENT_ROOT      $document_root2;
        }       

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        location / {
            root /home/wayvac/public;   
            index index.html index.htm index.php;
        }

        location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
            # Some basic cache-control for static files to be sent to the browser
            expires max;
            add_header Pragma public;
            add_header Cache-Control "public, must-revalidate, proxy-revalidate";
        }

        #include drop.conf;
        #include php.conf;
    }
}

저와 같은 문제가 발생하여 이 페이지를 찾는 사람이 있다면, 여기에서 답을 찾을 수 있습니다.

클릭해서 스스로 해결할 수 없는 분들을 위해...;)

조건:

NGINX 5 PHP 5.3 、 Ubuntu 、 Debian 、 PHP 5 5 . 4 、 502 Bad Gateway 오오 n 。은 「9000」을 실행하고 있다)에서하고 있는 를 찾습니다.netstat -lp또는 유사)는 아무것도 반환하지 않습니다.

해결 방법:

./etc/php5/fpm/pool.d/www.conf ' 매개 변수 같은 경우에는 '듣기')를해 두세요./var/run/php5-fpm.sock

; The address on which to accept FastCGI requests.
; Valid syntaxes are:
;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific address on
;                            a specific port;
;   'port'                 - to listen on a TCP socket to all addresses on a
;                            specific port;
;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = /var/run/php5-fpm.sock

vhost의 fastcgi_pass 변수를 방금 메모한 위치로 바꿉니다.

다음으로 symfony2 설정 예를 나타냅니다(여기서 취득).

  # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  location ~ ^/(app|app_dev)\.php(/|$) {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    fastcgi_param  HTTPS              off;
  }

다음과 같이 됩니다.

  # pass the PHP scripts to FastCGI server at /var/run/php5-fpm.sock
  location ~ ^/(app|app_dev)\.php(/|$) {
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    fastcgi_param  HTTPS              off;
  }

그런 다음 nginx를 재시작합니다.

sudo /etc/init.d/nginx restart

주의: 교환~ ^/(app|app_dev)\.php(/|$) {~ ^/index\.php(/|$) {SF2**가

이것으로 시간을 조금 절약할 수 있기를 바랍니다:)

편집

수도 요.listen = /var/run/php5-fpm.sock로로 합니다.listen = 127.0.0.1:9000/etc/php5/fpm/pool.d/www.confphp5-fpm (( ( vhosts ) 。 단, php5-fpm은 어떤 이유로 포트 9000에서 리슨하지 않고 소켓을 통해 실행되도록 변경되었습니다.

편집 2

502 에러가 아직 발생하고 있는 경우는, 다음의 회답을 참조해 주세요.

이러한 값을 설정해 보십시오. fast-cgi로 문제를 해결합니다.

fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;

비슷한 수정을 했지만, 가끔 501/502 에러가 나곤 했습니다(매일).

501 및 502 nginx 오류를 피하기 위한 /etc/php5/fpm/pool.d/www.conf 설정입니다.서버의 RAM은 16Gb.이 구성은 8 Gb RAM 서버용입니다.따라서...

sudo nano /etc/php5/fpm/pool.d/www.conf

다음으로 다음 값을 설정합니다.

pm.max_children = 70
pm.start_servers = 20
pm.min_spare_servers = 20
pm.max_spare_servers = 35
pm.max_requests = 500

변경 후 php-fpm을 재시작합니다.

sudo service php-fpm restart

저처럼 php-fpm을 업그레이드한 후 문제가 발생한 경우 다음을 시도해 보십시오. /etc/php5/fpm/pool.d/www.conf를 열어 다음 행을 주석 해제합니다.

listen.owner = www-data
listen.group = www-data
listen.mode = 0666

php-fpm을 재시작합니다.

마세요.php-fpm.인스톨 후에, 다음의 순서로 기동해 주세요.

# service php-fpm start
# chkconfig php-fpm on

이 문제를 해결하기 위해 고군분투하는 다른 사람들을 위해, 저는 UNIX 소켓 사용을 중단하고 싶지 않기 때문에 제안대로 타임아웃을 조정하려고 했습니다.많은 트러블 슈팅 후, 이 문제는 몇 달 전에 php-fpm에서 활성화한 APC 확장으로 인해 발생한다는 것을 알게 되었습니다.이 확장을 디세블로 하면 단속적인 502 에러가 해결됩니다.이렇게 하려면 , 다음의 행에 코멘트를 달아 주세요.

;extension = apc.so

이게 날 속였어!

에러 로그가 표시됩니다.기본적으로는 이 위치는 /var/log/nginx/error.log에 있습니다.

제 경우, 502는 다음 이유로 우선합니다.

GET /app_dev.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "symfony2.local"
2016/05/25 11:57:28 [error] 22889#22889: *3 upstream sent too big header while reading response header from upstream, client: 127.0.0.1, server: symfony2.local, request: "GET /app_dev.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "symfony2.local"
2016/05/25 11:57:29 [error] 22889#22889: *3 upstream sent too big header while reading response header from upstream, client: 127.0.0.1, server: symfony2.local, request: "GET /app_dev.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "symfony2.local"
2016/05/25 11:57:29 [error] 22889#22889: *3 upstream sent too big header while reading response header from upstream, client: 127.0.0.1, server: symfony2.local, request: "GET /app_dev.php HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock:", host: "symfony2.local"

우리가 정확히 뭐가 잘못됐는지 알게 되면, 고치면 돼.다음 오류의 경우 버퍼만 수정합니다.

fastcgi_buffers 16 512k; 
fastcgi_buffer_size 512k;

포트는 5.4에서 9001로 변경되어 nginx conf 및 php-fpm 설정에서 9000에서 9001로 변경되었을 뿐입니다.

이 팁이 다른 사람의 목숨을 구해주길 바란다.저 같은 경우에는 메모리가 부족하다는 것이 문제였지만, 조금밖에 생각할 수 없었습니다.그것 때문에 3시간을 허비했다.실행할 것을 권장합니다.

sudo htop

또는

sudo free -m

서버상에서 문제가 있는 요구를 실행하여 메모리가 부족하지 않은지 확인합니다.이 경우 스왑 파일을 생성해야 합니다(이미 파일을 가지고 있지 않은 경우).

이 튜토리얼에 따라 Ubuntu Server 14.04에서 스왑 파일을 작성했습니다.이 튜토리얼은 정상적으로 동작했습니다.

또한 이 에러는 MySQL에 json_encoded() 데이터를 쓸 때 발생할 수 있습니다.이를 회피하기 위해 JSON을 64_encode()로 설정합니다.디코딩 시 JSON 인코딩에 의해 값이 변경될 수 있습니다.Nb. 24는 24.00이 될 수 있습니다.

웹상의 모든 솔루션을 시도한 후 매우 간단한 방법으로 문제를 해결했습니다.처음에는 php-fpm 에러 로그를 체크했습니다.

cat /var/log/php5-fpm.log 

그리고 가장 반복된 오류는

" WARNING: [pool www] server reached pm.max_children setting (5), consider raising it "

PHP-fpm 풀 설정을 편집합니다.

nano /etc/php5/fpm/pool.d/www.conf

나는 이 라인을 청했다.

pm.max_children = 5

새로운 가치로

pm.max_children = 10

을 탑재한 VPS를 사람들과 마찬가지로 128MB의 VPS를 하는 것을 .다른 사람들과 마찬가지로 재사용을 생각하고 있었습니다.pm.max_children서버의 메모리 소비를 줄일 수 있지만 PHP-fpm 프로세스를 시작하기에는 설정이 너무 낮습니다.나는 이것이 내가 24시간 테스트와 실패 후에 이것을 발견했기 때문에 다른 사람들에게 도움이 되기를 바랍니다, 나의 웹호스트 지원은 문제를 해결할 수 없었습니다.

이 게임은 많이 늦었지만 서버에서 php를 업그레이드하면서 문제가 시작되었습니다..socket 파일을 삭제하고 서비스를 재시작할 수 있었습니다.그리고 모든 것이 잘 되었다.파일 크기가 0이고 소유권과 사용 권한은 동일하지만 작동했기 때문에 차이가 나는 이유는 알 수 없습니다.

Nginx 설정을 조작하기 전에 먼저 ChromePHP를 비활성화해 보십시오.

1 - app/config/config_dev.yml 열기

2 - 다음 행에 코멘트합니다.

chromephp:
    type:   chromephp
    level:  info

ChromePHP는 x-ChromePhp-Data 헤더에 json-encoded된 디버깅 정보를 패킹합니다.이것은 fastcgi를 사용한nginx 기본 설정에는 너무 큽니다.

파일을 (보통 NGINX vhost)에 있습니다.location ~ \.php$ { CGI 를 하면, 행이 있는 해 주세요. ) Fast CGI 음음 、 음음음:::: 。

proxy_buffer_size          128k;
proxy_buffers              4 256k;
proxy_busy_buffers_size    256k;
fastcgi_buffer_size        16k;
fastcgi_buffers            4 16k;

그 후 fpm과 nginx를 재시작하는 것을 잊지 마십시오.


추가:

NGINX vhost 경로

  • /etc/nginx/sites-enabled/(Linux).
  • '/usr/local/etc/nginx/sites-enabled/' - Mac

NGINX를 재시작합니다.

  • sudo service nginx restart(Linux).
  • brew service restart nginx(Mac)

FPM 재시작:

fpm 프로세스명을 확인합니다.-systemctl list-unit-files | grep fpm- Linux -brew services list | grep php(Mac)

다음에, 재기동합니다.

  • sudo service <service-name> restart(Linux).
  • brew services restart <service-name>(Mac)

이 답변이 도움이 될 수 있습니다.

nginx 오류: php5-fpm.sock에 연결하지 못했습니다(13: 권한 거부됨).

해결책은 /var/www/php/fpm/pool.d/www.conf에서 www-data를 nginx로 바꾸는 것이었습니다.

또한 소켓 자격 정보를 각각 수정합니다.

$ sudo chmod nginx:nginx /var/run/php/php7.2-fpm.sock

언급URL : https://stackoverflow.com/questions/10003978/php-fpm-and-nginx-502-bad-gateway

반응형