我有以下configuration:Apache 2.4,PHP的FPM,mod_proxy_fgci。 问题是我的configuration不能使用别名指令:我已经安装了phpredmin,但别名指令不能与ProxyPass一起使用。 有人能把我推向正确的方向吗?
这是configuration:
<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>
更新
我已经创build了一个额外的虚拟主机,我已经得到了phpredmin这个configuration工作:
<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>
Apache从上到下读取configuration文件。
如果find匹配的命令(比如proxypass),它将被执行,文件的其余部分将被丢弃。
为了在ProxyPass之前执行您的Alias命令,您需要将其放在文件的顶部。
<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>
这是简短的答案。 把下面的3行放在你的httpd.conf文件中,你可以很好的去做:
<FilesMatch \.php$> SetHandler "proxy:fcgi://127.0.0.1:9000" </FilesMatch>
在我的工作与你完全相同的configuration。