502 오류 Nginx 및 php5-fpm

502 오류 Nginx 및 php5-fpm

php5-fpm 및 nginx에서 이상한 502 문제가 발생했습니다. Nginx 가상 호스트 구성:

server {
    server_name _;
    listen 7777 default_server;
#        root /var/www/html;
    root /var/www/test_app;
#        index index.php;
    index index.php index.html index.htm;

            location / {
              try_files $uri /index.html;
            }

#   location / {
#                try_files $uri $uri/ =404;
#        }

    location ~ \.php$ {
    try_files $uri =404;
    include fastcgi_params;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_intercept_errors on;
    fastcgi_ignore_client_abort on;
    fastcgi_connect_timeout 60;
    fastcgi_send_timeout 180;
    fastcgi_read_timeout 180;
    fastcgi_buffer_size 128k;
    fastcgi_buffers 256 16k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;
    fastcgi_max_temp_file_size 0;
    fastcgi_pass unix:/var/run/php5-fpm.sock;

    }

}

php5-fpm에는 기본 구성이 있습니다. 방금 몇 가지 디버그 라인을 추가했습니다:

[www]
access.log = /var/log/php5-fpm/access.log
access.format = "%t \"%m %r%Q%q\" %s %{mili}dms %{kilo}Mkb %C%%"
catch_workers_output = yes
php_flag[display_errors] = on
php_admin_flag[log_errors] = true

/var/www/ 디렉토리는 www-data에 속하며 660개의 파일을 가지고 있습니다. 소켓 파일 /var/run/php5-fpm.sock이 존재합니다. /var/log/php5-fpm/error.log에는 흥미로운 내용이 없습니다.

[01-Jan-2018 20:29:44] NOTICE: fpm is running, pid 14336
[01-Jan-2018 20:29:44] NOTICE: ready to handle connections
[01-Jan-2018 20:29:44] NOTICE: systemd monitor interval set to 10000ms
[01-Jan-2018 20:50:40] NOTICE: Terminating ...
[01-Jan-2018 20:50:40] NOTICE: exiting, bye-bye!
[01-Jan-2018 20:50:41] NOTICE: configuration file /etc/php5/fpm/php-fpm.conf te$

[01-Jan-2018 20:50:41] NOTICE: fpm is running, pid 14463
[01-Jan-2018 20:50:41] NOTICE: ready to handle connections
[01-Jan-2018 20:50:41] NOTICE: systemd monitor interval set to 10000ms

그러나 nginx 로그에는 중복된 오류가 많이 있습니다.

sudo grep error /var/log/nginx/error.log
2018/01/01 20:50:43 [error] 14453#0: *4 rewrite or internal redirection cycle while internally redirecting to "/index.html", client: 44.33.22.11, server: _, request: "GET /favicon.ico HTTP/1.1", host: "11.22.33.44:7777", referrer: "http://11.22.33.44:7777/index.html"

/var/log/php5-fpm/access.log가 비어 있습니다. index.php는 간단한 한 줄짜리 phpinfo() 테스트 파일입니다. php-fpm에 문제가 있나요?

답변1

좋아, 스스로 대답하자면 버그를 발견했습니다. php5-fpm을 설치했을 때 잘못된 유닉스 소켓 경로가 포함된 이전 구성 파일이 있었습니다. /etc/php/fpm/pool.d/www.conf 파일에서 이 줄을 다음과 같이 수정합니다.

/var/run/php5-fpm.sock

phpinfo 페이지를 볼 수 있습니다.

관련 정보