我有以下配置:Apache 2.4、php-fpm、mod_proxy_fgci。问题是我的配置无法与别名指令配合使用:我已安装 phpredmin,但别名指令无法与 ProxyPass 配合使用。有人能给我指点迷津吗?
这是配置:
<VirtualHost *:80>
ServerName default
# Directory
DocumentRoot /var/www/default/wwwroot
<Directory /var/www/default/wwwroot>
Options +FollowSymLinks +ExecCGI +Includes
AllowOverride All
Require all granted
</Directory>
# PHP-FPM Server
<LocationMatch "^/(.*\.php(/.*)?)$">
ProxyPass fcgi://127.0.0.1:9000/var/www/default/wwwroot/$1
</LocationMatch>
# Directory indexes
<IfModule dir_module>
DirectoryIndex index.htm index.html index.shtml index.php index.phtml
</IfModule>
Alias /phpredmin /var/www/default/wwwroot/phpredmin/public
<Directory "/var/www/default/wwwroot/phpredmin/">
AllowOverride All
require ip 127.0.0.1
</Directory>
</VirtualHost>
更新
我创建了一个额外的 vhost,并且让 phpredmin 使用以下配置:
<VirtualHost *:80>
ServerName phpredmin.example.com
DocumentRoot /var/www/default/wwwroot/phpredmin
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
LogLevel alert
DirectoryIndex index.php
ServerSignature Off
RewriteEngine on
<Directory /var/www/default/wwwroot/phpredmin>
Options -Indexes
require ip 192.168.2.0/24
require ip 192.168.10.0/24
</Directory>
Alias /phpredmin /var/www/default/wwwroot/phpredmin/public
<Directory /var/www/default/wwwroot/phpredmin/public>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . fcgi://127.0.0.1:9000/var/www/default/wwwroot/phpredmin/public/index.php [P,L]
RewriteRule ^/?(.*\.php)$ fcgi://127.0.0.1:9000/var/www/default/wwwroot/phpredmin/public/$1 [P,L]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^/?(.*)$ fcgi://127.0.0.1:9000/var/www/default/wwwroot/phpredmin/public/$1 [P,L]
DirectoryIndex disabled
ProxyErrorOverride on
</Directory>
答案1
Apache 从上到下读取配置文件。
如果找到匹配的命令(例如您的代理密码),则会执行该命令并丢弃文件的其余部分。
为了使您的 Alias 命令在 ProxyPass 之前执行,您需要将其放在文件顶部。
<VirtualHost *:80>
ServerName default
# Directory
DocumentRoot /var/www/default/wwwroot
<Directory /var/www/default/wwwroot>
Options +FollowSymLinks +ExecCGI +Includes
AllowOverride All
Require all granted
</Directory>
Alias /phpredmin /var/www/default/wwwroot/phpredmin/public
<Directory "/var/www/default/wwwroot/phpredmin/">
AllowOverride All
require ip 127.0.0.1
</Directory>
# PHP-FPM Server
<LocationMatch "^/(.*\.php(/.*)?)$">
ProxyPass fcgi://127.0.0.1:9000/var/www/default/wwwroot/$1
</LocationMatch>
# Directory indexes
<IfModule dir_module>
DirectoryIndex index.htm index.html index.shtml index.php index.phtml
</IfModule>
</VirtualHost>
答案2
答案很简单。将以下 3 行放入您的 httpd.conf 文件中,即可开始:
<FilesMatch \.php$>
SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>
对我来说,它的配置和你的完全相同。