我们最近把我们的Web服务器之一切换到apache 2.4,并通过php-fpm和mod_proxy_fcgi运行PHP。 大多数一切运作良好,但有一个问题我还不明白。 我们的一个网站正在运行WordPress,它在.htaccess文件中带来了一个很好的重写规则列表。 而且似乎这些在vhost安装中的ProxyPass指令不能很好地工作。
我们的虚拟主机包含以下configuration:
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。
我认为这是因为存在一个优先问题 – ProxyPass规则在所有的RewriteRules都被解决之前触发。
我受阻 – 可能是什么原因?
我find了这个解决scheme,我不知道是不是最好的方法,但为我工作。
删除行:
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.2:9126/<path>/$1
在你的指令中join这个:
<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文件将redirect到fcgi代理。
而“ RewriteOptions InheritBefore ”这强制当前configurationinheritance父configuration,但应用在子作用域(目录中的.htaccess)中指定的规则之前。 是唯一的方法,我发现有fcgiconfiguration和客户端.htaccessconfiguration之间的兼容性。
要控制代理所需的其他参数,请执行以下操作:
<IfModule mod_proxy_fcgi.c> <Proxy fcgi://127.0.0.2:9126> ProxySet timeout=1800 disablereuse=on </Proxy> </IfModule>
将重写逻辑移入ProxyPassMatchexpression式中。 在vhostconfiguration文件之前添加两个额外的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
通过ProxyPassMatch , .htaccess文件将被忽略。 尝试使用FilesMatch和SetHandler来代替,如此处和此处所述 。