FastCGI에 ProxyPassMatch를 사용하면 포트 9000에서 연결이 거부됩니다.

FastCGI에 ProxyPassMatch를 사용하면 포트 9000에서 연결이 거부됩니다.

이것이 php, apache 또는 iptables 구성 문제인지 확실하지 않지만 파일에 액세스하려고 하면 다음 오류가 발생합니다 .php. 진단에 도움이 되는 추가 정보가 필요하면 알려주시기 바랍니다. 다음에 무엇을 확인해야 할지 모르겠습니다. 감사합니다.

error.log:

[Thu May 08 16:43:15.392784 2014] [proxy:error] [pid 23112] (111)Connection refused: AH00957: FCGI: attempt to connect to 127.0.0.1:9000 (*) failed
[Thu May 08 16:43:15.392891 2014] [proxy_fcgi:error] [pid 23112] [client 74.164.254.206:52788] AH01079: failed to make connection to backend: 127.0.0.1

나는 팔로우했다이 가이드실행 중인 PHP 5.5.9 및 Apache 2.4.7

mod_proxy및 모듈이 로드되어 있습니다 mod_proxy_so.

# grep LoadModule /etc/apache2/apache2.conf
LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_fcgi_module /usr/lib/apache2/modules/mod_proxy_fcgi.so 

다음은 ProxyPassMatch 지시어입니다:

ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/$1

또한 다음 지시문과 함께 UDS를 사용하려고 시도했지만 Apache 구성 테스트에서 절대 URL에 대해 불평합니다.

ProxyPassMatch ^/(.*\.php(/.*)?)$ unix:/var/run/php5-fpm.sock|fcgi://127.0.0.1:80/path/to/root/

여기는iptables -L

Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere
REJECT     all  --  anywhere             127.0.0.0/8          reject-with icmp-port-   unreachable
ACCEPT     all  --  anywhere             anywhere             state RELATED,ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:http
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:https
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:finger
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:smtp
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:urd
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:pop3
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:pop3s
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:imap2
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:imaps
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:submission
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:webmin
ACCEPT     tcp  --  anywhere             anywhere             state NEW tcp dpt:ssh
ACCEPT     icmp --  anywhere             anywhere
LOG        all  --  anywhere             anywhere             limit: avg 5/min burst 5   LOG level debug prefix "iptables denied: "
DROP       all  --  anywhere             anywhere

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
DROP       all  --  anywhere             anywhere

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere

답변1

PHP-FPM실행 중인지 확인하세요 . 오류 로그에는 apache127.0.0.1:9000에 연결할 수 없다고 나와 있습니다. 실행하면 (어쩌면) 오류가 발생합니다.

또한 PHP-FPM소켓을 통해 실행 중인지 확인하십시오. 어쩌면 실행 중이지만 TCP/IP 스택을 수신하지 않을 수도 있습니다.

답변2

Chris의 의견에 따르면, apache/php가 소켓 연결을 지원하는지(apache > 2.4.10이면 지원할 수 있는 것처럼 보임) 추가하고 싶었고, 이를 Apache 구성에서 사용하도록 변경할 수도 있습니다. 나는 청취 라인에서 어떤 소켓이 듣고 있는지 확인하기 위해 PHP vi /etc/php/7.0/fpm/pool.d/www.conf 파일을 확인했습니다.

listen = /run/php/php7.0-fpm.sock

그런 다음 이를 /etc/apache2/sites-enabled/000-default.conf 파일(또는 활성화하려는 웹 사이트)에 추가했습니다...

<FilesMatch \.php$>
    # 2.4.10+ can proxy to unix socket
    # SetHandler "proxy:unix:/var/run/php?-fpm.sock|fcgi://localhost/"

    # Else we can just use a tcp socket:
    # SetHandler "proxy:fcgi://127.0.0.1:9000"

    SetHandler "proxy:unix:/run/php/php7.0-fpm.sock|fcgi://localhost/"
</FilesMatch>

그런 다음 웹 서버를 다시 시작하면 index.php가 표시됩니다.

sudo service apache2 restart

관련 정보