Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have Apache httpd on port 80 and Morbo httpd server on port 3000 serving perl Mojolicious code. Morbo is available only from localhost.

Now I want to set up virtual host with proxy so that static files would be served by Apache and dynamic content would be serverd by Morbo.

This is my virtual host config:

<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>

The problem is that when I try to access http://mojo.myhost.com/ Apache subrequ is issued by Apache and request sent to Morbo is http://localhost:3000/error/noindex.html and not http://localhost:3000/.

Here is part of 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]

I added NS flag to RewriteRule but subreq still modifies the URL before it is passed to Morbo. How can I get Apache to pass / instead of /error/noindex.html to Morbo?

If both RewriteCond are removed from virtualhost config then it works but static files are also serverd by Morbo (which I don't like so much).

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Here's what happens, step by step:

  1. The server gets a request for /
  2. The server checks the -f condition, and finds that / is not a file, so it matches the condition.
  3. The server checks the -d condition, and finds that / is a directory, so it doesn't match the condition.
  4. Since it doesn't match the second condition, the server tries to process it as a local file/directory. A resource ending in / should have an index file; so it tries looking for all the index files listed.
  5. Since it can't find an index file, it wants to show you /error/noindex.html instead.
  6. We now go back to checking the rewrite conditions, and this time we match both - there's neither a file nor a directory called /error/noindex.html, so this time the proxy request is made

The solution:

Add a RewriteRule that matches only the empty / and have that one do the Rewrite. Example:

RewriteRule   ^/$  http://localhost:3000 [NS,P,L]
ProxyPassReverse  /  http://mojo.myhost.com

This matches a request for only /.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.