我有端口80上的Apache httpd和端口3000上的Morbo httpd服务器服务perl Mojolicious代码。 Morbo只能从本地主机上获得。
现在我想要使用代理来设置虚拟主机,这样静态文件将由Apache提供,dynamic内容将由Morbo提供服务。
这是我的虚拟主机configuration:
<VirtualHost *:80> ServerName mojo.myhost.com DocumentRoot /opt/mojo/public RewriteEngine on RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d RewriteRule ^(.*) http://localhost:3000$1 [NS,P,L] ProxyPassReverse / http://mojo.myhost.com </VirtualHost>
问题是,当我尝试访问http://mojo.myhost.com/ Apache的subrequ由Apache发出,请求发送到Morbo是http://localhost:3000/error/noindex.html而不是http://localhost:3000/ 。
这里是mod-rewrite log的一部分:
[rid#2b20905c58e0/initial] (2) init rewrite engine with requested uri / [rid#2b20905c58e0/initial] (3) applying pattern '^(.*)' to uri '/' [rid#2b20905c58e0/initial] (4) RewriteCond: input='/opt/mojo/public/' pattern='!-f' => matched [rid#2b20905c58e0/initial] (4) RewriteCond: input='/opt/mojo/public/' pattern='!-d' => not-matched [rid#2b20905c58e0/initial] (1) pass through / [rid#2b20905cb910/subreq] (2) init rewrite engine with requested uri /index.php [rid#2b20905cb910/subreq] (1) pass through /index.php [rid#2b20905cd920/subreq] (2) init rewrite engine with requested uri /index.html [rid#2b20905cd920/subreq] (1) pass through /index.html [rid#2b20905cb910/subreq] (2) init rewrite engine with requested uri /index.html.var [rid#2b20905cb910/subreq] (1) pass through /index.html.var [rid#2b20905cd920/subreq] (2) init rewrite engine with requested uri /index.htm [rid#2b20905cd920/subreq] (1) pass through /index.htm [rid#2b20905caf40/initial/redir#1] (2) init rewrite engine with requested uri /error/noindex.html [rid#2b20905caf40/initial/redir#1] (3) applying pattern '^(.*)' to uri '/error/noindex.html' [rid#2b20905caf40/initial/redir#1] (4) RewriteCond: input='/opt/mojo/public/error/noindex.html' pattern='!-f' => matched [rid#2b20905caf40/initial/redir#1] (4) RewriteCond: input='/opt/mojo/public/error/noindex.html' pattern='!-d' => matched [rid#2b20905caf40/initial/redir#1] (2) rewrite '/error/noindex.html' -> 'http://localhost:3000/error/noindex.html' [rid#2b20905caf40/initial/redir#1] (2) forcing proxy-throughput with http://localhost:3000/error/noindex.html [rid#2b20905caf40/initial/redir#1] (1) go-ahead with proxy request proxy:http://localhost:3000/error/noindex.html [OK]
我将NS标志添加到RewriteRule但是在传递给Morbo之前,subreq仍然会修改URL。 我怎样才能让Apache通过/而不是/ / error / noindex.html Morbo?
如果两个RewriteCond从虚拟主机configuration中删除,那么它的工作,但静态文件也由Morbo服务器(我不喜欢这么多)。
这是发生了什么,一步一步:
/ -f条件,发现/不是一个文件,所以它符合条件。 -d条件,发现/ 是一个目录,所以它不符合条件。 /结尾的资源应该有一个索引文件; 所以它会尝试查找列出的所有索引文件。 /error/noindex.html 。 /error/noindex.html的目录,所以这次代理请求 解决scheme:
添加一个只匹配空/的RewriteRule,让那个人重写。 例:
RewriteRule ^/$ http://localhost:3000 [NS,P,L] ProxyPassReverse / http://mojo.myhost.com
这只匹配/的请求。