2014-04-11 83 views
1

我想用HHVM配置Apache。作为其中的一部分,我需要配置重写规则。我已经在FastCGI模式下将HHVM作为守护进程启动。我已启用Apache模块mod_proxy,mod_proxy_fcgimod_rewriteApache 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规则。

如何让这些功能一起使用?

回答

0

把这一个弄出来:用ProxyPassMatch,不用打扰mod_rewrite

像这样:

<VirtualHost *:80> 
    DocumentRoot /app 

    ProxyPassMatch ^.*$ fcgi://127.0.0.1:9000/app/foo.php 

    <Directory /app> 
    Require all granted 
    </Directory> 
</VirtualHost> 
0

我有一个类似的问题,并没有不使用mod_rewrite的奢侈品。 如果在启用'mod_remoteip'的同时将mod_geoip选项'GeoIPScanProxyHeaders'设置为'On',则会发现mod_geoip和mod_rewrite之间存在冲突。

'GeoIPScanProxyHeaders'是获取'mod_geoip'使用的客户端IP地址的设置。事实证明,mod_geoip选项'GeoIPScanProxyHeaders'不应该在Apache 2.4上启用,如果'mod_remoteip'被加载。 'mod_remoteip'应该是首选,'mod_geoip'将使用'mod_remoteip'的发现。