【发布时间】:2014-05-26 05:27:19
【问题描述】:
我正在尝试使用 HHVM 配置 Apache。作为其中的一部分,我需要配置重写规则。我已将 HHVM 作为 FastCGI 模式下的守护进程启动。我已启用 Apache 模块 mod_proxy、mod_proxy_fcgi 和 mod_rewrite。
首先,没有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 提供普通的 /app/foo.php 文件:
$ curl http://localhost/blah
<?php
echo "HELLO\n";
也就是说,现在它似乎尊重重写规则,但现在忽略了ProxyPass 规则。
如何让它们一起工作?
【问题讨论】:
标签: mod-rewrite apache2 fastcgi mod-proxy