我想用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
規則。
如何讓這些功能一起使用?