PHP-FPM + Apache2 보안

PHP-FPM + Apache2 보안

내 질문은 2년 전 Luis Machuca의 질문과 거의 같습니다(Apache + php-fpm: 풀별, 사용자 프로젝트별 적절한 권한이 있습니까?), 그러나 몇 가지 추가 조건이 있습니다.

또한 Apache(v2.4.55) 및 php7.4-fpm에 의해 관리되도록 서버(내 것은 Ubuntu 22.04 시스템)를 구성했습니다. 현재 구성에서는 각 가상 호스트를 특정 php-fpm 풀로 나누고 각 풀을 다른 사용자가 실행할 수 있습니다.

모든 것이 잘 작동하지만 사용자 제어 권한(또는 open_basedir 기반)에만 관련된 보안은 shell_exec(필요한 것)가 내부 구성 파일에 액세스 /etc하거나 ls -l /var/.

그래서 제가 원하는 것은 사용자가 Linux 표준 폴더를 둘러볼 수 없도록 하는 방법입니다.

나는 다음과 같은 지점에 전화하고 싶지 않습니다.

setfacl -Rm u:user_site1:--- /;
setfacl -Rm d:u:user_site1:--- /;

그런 다음 각 기본 폴더를 하나씩 인증합니다. 너무 지저분해 보입니다.

그래서 각 풀에서 chroot를 사용하려고 생각했지만 경로와 관련된 문제가 항상 있고 모든 온라인 솔루션에서 포트 9000을 기반으로 호출을 AH01071: Got error 'Primary script unknown'수정하라고 하지만 소켓을 사용하므로 그렇게 할 수 없으며 이를 변경하고 싶지 않습니다. 환경.ProxyPassMatchSetHandler

가능한 기술은 무엇입니까? 정말로 SELinux를 설치해야 합니까?

아래에서는 상황을 더 잘 이해하기 위해 구성을 추가했습니다.

/etc/apache2/sites-enabled/www.site.com.conf

<VirtualHost *:80>
    Protocols h2 h2c http/1.1
    H2Direct on
    ServerAdmin [email protected]
    ServerName www.site.com
    DocumentRoot /var/www/vhosts/www.site.com/httpdocs
    ErrorLog /var/www/vhosts/www.site.com/log/error.log
    CustomLog /var/www/vhosts/www.site.com/log/access.log combined
    <FilesMatch ".+\.ph(ar|p|tml)$">
        SetHandler "proxy:unix:/run/php/php7.4-fpm-www_site_com.sock|fcgi://localhost"
    </FilesMatch>
</VirtualHost>
<VirtualHost *:443>
    Protocols h2 h2c http/1.1
        H2Direct on
        ServerAdmin [email protected]
        ServerName www.site.com
    DocumentRoot /var/www/vhosts/www.site.com/httpdocs
    ErrorLog /var/www/vhosts/www.site.com/log/error_ssl.log
    CustomLog /var/www/vhosts/www.site.com/log/access_ssl.log combined
    SSLEngine on
    SSLCertificateFile /etc/ssl/certs/www.site.com.crt
    SSLCertificateKeyFile   /etc/ssl/private/www.site.com.key
    <FilesMatch "\.(?:cgi|shtml|phtml|php)$">
        SSLOptions +StdEnvVars
    </FilesMatch>
    <Directory /usr/lib/cgi-bin>
        SSLOptions +StdEnvVars
    </Directory>
    <FilesMatch ".+\.ph(ar|p|tml)$">
        SetHandler "proxy:unix:/run/php/php7.4-fpm-www_site_com.sock|fcgi://localhost"
    </FilesMatch>
</VirtualHost>

/etc/php/7.4/fpm/php-fpm.conf

[global]
pid = /run/php/php7.4-fpm.pid
error_log = "syslog"
syslog.ident = php-fpm
include=/etc/php/7.4/fpm/pool.d/*.conf

/etc/php/7.4/fpm/pool.d/www_site_com.conf

[www.site.com]
user = user_site1
group = user_site1
listen = /run/php/php7.4-fpm-www_site_com.sock
listen.owner = user_site1
listen.group = www-data
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3

ベストアンサー1

おすすめ記事