태그 보관물: apache-2.4

apache-2.4

htaccess의 Apache 2.4 mod_proxy_fcgi 및 RewriteRules 이해 : ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.2:9126/<path>/$1 대부분의 경우

우리는 최근 웹 서버 중 하나를 아파치 2.4로 전환하고 php-fpm 및 mod_proxy_fcgi를 통해 PHP를 실행했습니다. 대부분의 모든 것이 잘 작동하지만 아직 이해하지 못하는 한 가지 문제가 있습니다. 우리 사이트 중 하나가 WordPress를 실행 중이며 .htaccess 파일에 좋은 다시 쓰기 규칙 목록을 제공합니다. 그리고 그것들은 vhost 설정에서 ProxyPass 지시문과 잘 작동하지 않는 것 같습니다.

우리의 호스트는 다음과 같은 구성을 포함합니다 :

ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.2:9126/<path>/$1

대부분의 경우 작동합니다.

이제 htaccess 파일은 다음을 수행합니다.

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule  ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule  ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

사이트가 하위 디렉토리의 멀티 블로그이므로 URL /blogname/wp-admin/load-styles.php?xxxx는 wp-admin / load-styles.php? xxx (두 번째 다시 쓰기 규칙)로 다시 작성해야한다는 것을 읽었습니다. 그러나 mod_proxy 로그를 보면 실제로 전달되는 요청은 /blogname/wp-admin/load-styles.php입니다.

우선 순위 문제가 있으므로 이것을 읽었습니다. 모든 RewriteRules가 해결되기 전에 ProxyPass 규칙이 실행됩니다.

나는 스티 미되었습니다-원인이 무엇입니까?



답변

이 솔루션을 찾았는데 최선의 방법인지 모르겠지만 저에게 효과적입니다.

  1. 라인을 제거하십시오.

    ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.2:9126/<path>/$1
    
  2. 지시문에 이것을 추가하십시오.

    <Directory /var/www/yoursiste.com>
        Options -Indexes +FollowSymLinks -ExecCGI +MultiViews
    
        AllowOverride All
    
        <IfModule mod_proxy_fcgi.c>
            RewriteEngine On
            RewriteBase /
            RewriteOptions InheritBefore
            RewriteCond %{REQUEST_FILENAME} -f
            RewriteRule ^([^\.]+\.php)$ fcgi://127.0.0.2:9126/var/www/yoursite.com/$1 [L,P]
        </IfModule>
    
        Order allow,deny
        allow from all
    
        <IfVersion >= 2.4>
            Require all granted
        </IfVersion>
    </Directory>
    

    모든 실제 PHP 파일은 fcgi 프록시로 리디렉션됩니다.

    RewriteOptions InheritBefore “이렇게하면 현재 구성이 상위 구성을 상속하지만 하위 범위에 지정된 규칙 (디렉토리의 .htaccess)보다 먼저 적용됩니다. fcgi 구성과 클라이언트 .htaccess 구성간에 호환성이있는 유일한 방법입니다.

  3. 프록시에 필요한 다른 매개 변수를 제어하려면 다음을 수행하십시오.

    <IfModule mod_proxy_fcgi.c>
        <Proxy fcgi://127.0.0.2:9126>
            ProxySet timeout=1800 disablereuse=on
        </Proxy>
    </IfModule>
    

답변

를 사용 ProxyPassMatch하면 .htaccess파일이 무시됩니다. herehere 설명 된대로 FilesMatchSetHandler대신 사용해보십시오 .


답변

다시 쓰기 논리를 ProxyPassMatch 표현식으로 이동하십시오. 다음과 같이 vhost 설정의 행 앞에 두 개의 ProxyPassMatch 행을 추가하십시오.

ProxyPassMatch ^/([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes)/.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/<path>/$2
ProxyPassMatch ^/([_0-9a-zA-Z-]+/)?(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/<path>/$2
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/<path>/$1


답변