
잘못 구성된 Apache 상자가 PHP 파일을 정적 일반 텍스트로 제공하고 잠재적으로 자격 증명 등을 포기할 수 있는 드문 상황을 처리하는 데 사용하는 Apache 2.4 구성 섹션이 있습니다.
<IfModule !mod_php5.c>
<IfModule !mod_php7.c>
<Files "*.php">
Require all denied
</Files>
</IfModule>
</IfModule>
해당 지시어는 php 모듈이 있는지 확인하고 둘 중 하나도 찾지 못하면 페이지를 제공하지 않습니다.
그러나 현재 centos-8용 httpd 2.4 빌드에서는 php-fpm이 php용 핸들러를 구성하는 기본 방법이며 php용 모듈을 로드하지 않습니다.
<IfModule !mod_php5.c>
<IfModule !mod_php7.c>
# Enable http authorization headers
SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1
<FilesMatch \.(php|phar)$>
SetHandler "proxy:unix:/run/php-fpm/www.sock|fcgi://localhost"
</FilesMatch>
</IfModule>
</IfModule>
불행히도, Proxy_fcgi 모듈은 httpd에 의해 자동으로 로드되므로 php-fpm이 구성되었는지 여부를 나타내는 데는 유용하지 않습니다.
[root@web httpd]# rpm -q --whatprovides /usr/lib64/httpd/modules/mod_proxy_fcgi.so
httpd-2.4.37-39.module_el8.4.0+778+c970deab.x86_64
에 따르면문서변수 가 있습니다 HANDLER
:
HANDLER 응답을 생성하는 핸들러의 이름
... 다음 중 하나를 반환해야 합니다.내장 핸들러에서
default-handler: Send the file using the default_handler(), which is the handler used by default to handle static content. (core) send-as-is: Send file with HTTP headers as is. (mod_asis) cgi-script: Treat the file as a CGI script. (mod_cgi) imap-file: Parse as an imagemap rule file. (mod_imagemap) server-info: Get the server's configuration information. (mod_info) server-status: Get the server's status report. (mod_status) type-map: Parse as a type map file for content negotiation. (mod_negotiation)
그러나 이에 대한 일치 시도는 성공하지 못했습니다. 예를 들어 다음은 작동하지 않습니다.
<FilesMatch \.(php|phar)$>
<If "%{HANDLER} == 'default-handler'">
Require all denied
</If>
</FilesMatch>
어떤 제안이라도 감사하겠습니다.
편집하다
나는 php-fpm이 설치된 상태에서 %{HANDLER} 변수의 값을 덤프했지만 그렇지 않았습니다.
<IfModule headers_module>
Header always set X-HANDLER "expr=%{HANDLER}"
</IfModule>
그리고 다음 헤더를 반환했습니다.
X-HANDLER: text/plain # no php-fpm
X-HANDLER: proxy:unix:/run/php-fpm/www.sock|fcgi://localhost # with php-fpm
그래서 테스트를 다음과 같이 업데이트했습니다.
<IfModule !mod_php5.c>
<IfModule !mod_php7.c>
<If "%{HANDLER} == 'text/plain'">
<Files "*.php">
Require all denied
</Files>
</If>
</IfModule>
</IfModule>
그러나 그것도 작동하지 않습니다