我想用HHVM配置Apache。作为其中的一部分,我需要配置重写规则。我已经在FastCGI模式下将HHVM作为守护进程启动。我已启用Apache模块mod_proxy
,mod_proxy_fcgi
和mod_rewrite
。Apache mod_rewrite不能与FastCGI一起工作
首先,如果没有mod_rewrite
,我有这个虚拟主机:
<VirtualHost *:80>
DocumentRoot /app
ProxyPass/fcgi://127.0.0.1:9000/app/
</VirtualHost>
我有一个文件/app/foo.php
它看起来像这样:
<?php echo "HELLO\n";
正因为如此,我可以使用访问:
$ curl http://localhost/foo.php
HELLO
现在,配置我的重写规则后:
<VirtualHost *:80>
DocumentRoot /app
ProxyPass/fcgi://127.0.0.1:9000/app/
RewriteEngine on
RewriteRule ^(.*)$ /foo.php
</VirtualHost>
我希望发生的是,所有的请求,现在导致foo.php
文件的执行,输出HELLO
。
然而,是什么发生的事情是,我给出一个HTTP 403,不只是要求/foo.php
,但对于任何要求:
$ curl http://localhost/foo.php
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /foo.php
on this server.</p>
<hr>
<address>Apache/2.4.6 (Ubuntu) Server at localhost Port 80</address>
</body></html>
$ curl http://localhost/blah
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /blah
on this server.</p>
<hr>
<address>Apache/2.4.6 (Ubuntu) Server at localhost Port 80</address>
</body></html>
Apache的错误日志显示我:
$ tail -2 /var/log/apache2/error.log
[Fri Apr 11 21:30:20.645439 2014] [authz_core:error] [pid 5090:tid 140114499983104] [client 127.0.0.1:39056] AH01630: client denied by server configuration: /app/foo.php
[Fri Apr 11 21:30:23.281610 2014] [authz_core:error] [pid 5090:tid 140114616588032] [client 127.0.0.1:39057] AH01630: client denied by server configuration: /app/foo.php
在此之后,我设置了目录访问权限:
<VirtualHost *:80>
DocumentRoot /app
ProxyPass/fcgi://127.0.0.1:9000/app/
<Directory /app>
Require all granted
</Directory>
RewriteEngine on
RewriteRule ^(.*)$ /foo.php
</VirtualHost>
现在Apache服务器ES平原/app/foo.php
文件:
$ curl http://localhost/blah
<?php
echo "HELLO\n";
也就是说,现在看来要尊重重写规则,但现在忽略ProxyPass
规则。
如何让这些功能一起使用?