2014-04-11 161 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'的發現。