Apache 2.4 + PHP-FPM + Unix 소켓을 사용하는 ProxyPassMatch

Apache 2.4 + PHP-FPM + Unix 소켓을 사용하는 ProxyPassMatch

Unix 소켓을 사용하여 Apache v2.4 + PHP-FPM + ProxyPassMatch를 설정하려고 합니다.

Debian 9 Stretch, PHP v5.6.37, PHP v7.0.31, Apache v2.4.25를 사용합니다.

내 가상 호스트 설정은 다음과 같습니다(000-default.conf):

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName local.lc

    DocumentRoot /var/www

    ProxyPassMatch "^/(.*\.php(/.*)?)$" "unix:/var/run/php5.6-fpm.sock|fcgi://localhost/var/www/"

    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

다음 명령을 실행했습니다.

sudo apt-get install php7.0-cli php7.0-fpm php-pear libapache2-mod-fcgid
sudo apt install software-properties-common
# add repo to get PHP5
sudo apt-get -y install apt-transport-https lsb-release ca-certificates
sudo curl https://packages.sury.org/php/apt.gpg | apt-key add -
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
sudo echo 'deb https://packages.sury.org/php/ stretch main' > /etc/apt/sources.list.d/deb.sury.org.list
sudo apt-get update
sudo apt-get install php5.6-cli php5.6-fpm
sudo apt-get install php7.0 php7.0-fpm
sudo a2enconf php5.6-fpm
sudo systemctl reload apache2
sudo a2dismod php5 php7 php5.6 php7.0 mpm_prefork
sudo a2enmod actions alias proxy_fcgi mpm_worker
sudo systemctl restart apache2 php5.6-fpm php7.0-fpm

다음을 사용하여 변경 후 서버가 다시 시작됩니다.

sudo systemctl restart apache2 php5.6-fpm php7.0-fpm

로드할 때 빈 페이지가 나타납니다.

http://local.lc/

내 Windows 기반 개발 컴퓨터의 웹 사이트. local.lc는 "hosts" 파일에 있습니다.

로그(/var/log/apache2/error.log)에 다음이 표시됩니다.

[Tue Aug 28 23:24:26.685004 2018] [mpm_worker:notice] [pid 43104:tid 140487559849152] AH00295: caught SIGTERM, shutting down
[Tue Aug 28 23:24:27.001054 2018] [:notice] [pid 43531:tid 139833116394688] ModSecurity for Apache/2.9.1 (http://www.modsecurity.org/) configured.
[Tue Aug 28 23:24:27.001189 2018] [:notice] [pid 43531:tid 139833116394688] ModSecurity: APR compiled version="1.5.2"; loaded version="1.5.2"
[Tue Aug 28 23:24:27.001205 2018] [:notice] [pid 43531:tid 139833116394688] ModSecurity: PCRE compiled version="8.39 "; loaded version="8.39 2016-06-14"
[Tue Aug 28 23:24:27.001223 2018] [:notice] [pid 43531:tid 139833116394688] ModSecurity: LUA compiled version="Lua 5.1"
[Tue Aug 28 23:24:27.001236 2018] [:notice] [pid 43531:tid 139833116394688] ModSecurity: YAJL compiled version="2.1.0"
[Tue Aug 28 23:24:27.001248 2018] [:notice] [pid 43531:tid 139833116394688] ModSecurity: LIBXML compiled version="2.9.4"
[Tue Aug 28 23:24:27.001498 2018] [:notice] [pid 43531:tid 139833116394688] ModSecurity: StatusEngine call: "2.9.1,Apache/2.4.25 (Debian),1.5.2/1.5.2,8.39/8.39 2016-06-14,Lua 5.1,2.9.4,cb"
[Tue Aug 28 23:24:27.135554 2018] [:notice] [pid 43531:tid 139833116394688] ModSecurity: StatusEngine call successfully sent. For more information visit: http://status.modsecurity.org/
[Tue Aug 28 23:24:28.005175 2018] [mpm_worker:notice] [pid 43532:tid 139833116394688] AH00292: Apache/2.4.25 (Debian) OpenSSL/1.0.2l mod_fcgid/2.3.9 configured -- resuming normal operations
[Tue Aug 28 23:24:28.005270 2018] [core:notice] [pid 43532:tid 139833116394688] AH00094: Command line: '/usr/sbin/apache2'

로그에 도움이 되는 내용이 없습니다.

무엇이 잘못되었을지 아시나요?

기본 페이지가 로드되지 않는 이유는 무엇입니까?

답변1

DirectoryIndex구성에 지시어가 누락되었으므로 다음과 같은 URL을 요청할 때http://local.lc/Apache는 디렉토리의 내용만 표시하는 대신(아마도 사용자가 원하는 것이 아닐 수 있음) 디스크에서 어떤 파일을 찾아 제공해야 할지 모릅니다.

PHP-FPM을 사용하고 있다면 PHP-FPM에서 처리해야 하는 것과 DirectoryIndex유사한 것으로 설정해야 할 것입니다 .index.php

유틸리티 와 같은 것을 사용하여 PHP-FPM을 직접 테스트하면 cgi-fcgi여전히 작동하지 않는 경우 Apache를 우회할 수 있습니다.

답변2

액세스해도 http://local.lc/index.html페이지가 발생하지 않았으며 error.log에 오류도 발생하지 않았습니다.

DirectoryIndex@bodgit이 제안한 지시어 로 이 문제를 수정한 후 로드하면 http://local.lc/index.phperror.log에 오류가 발생합니다.

error.log를 살펴보면 다음과 같은 오류 메시지가 표시됩니다.

No such file or directory: AH02454: FCGI: attempt to connect to Unix domain socket /var/run/php5.6-fpm.sock (localhost) failed".

경로 를 확인하면 /var/run/php5.6-fpm.sock찾을 수 없지만 발견 /var/run/php/php5.6-fpm.sock되었습니다.

경로는 내 virtualhost 설정에서 다음(000-default.conf)으로 수정되었습니다.

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName local.lc

    DocumentRoot /var/www

    ProxyPassMatch "^/(.*\.php(/.*)?)$" "unix:/var/run/php/php5.6-fpm.sock|fcgi://localhost/var/www/"

    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

따라서 vhost 구성 파일에서 경로를 수정한 후 http://local.lc/index.php페이지를 로드하면 이제 다음이 표시됩니다.

"효과가있다!".

문제가 해결되었습니다.

관련 정보