Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

First off, this is my first go at apache, so please forgive my beginingingismness :)

My basic setup is as such: gets sent to my static IP via a CNAME entry at godaddy's DNS manager. It hits my Ubuntu 10 LTS server running Apache2.

I have a virtual host entry that directs that request to the proper /var/www/mysub folder. I don't have any content in there, but I added a line to the "It Works" page so I'd know if I got there successfully. I also have a Mac Mini running a wiki server on the same local network as the Ubuntu server.

I'd like to hit my Mini server instead of the /var/www/mysub folder.

After much reading on this site and others, I've managed to do it... kind of.

I have the following in my /var/www/mysub/.htacess, which I found in another SF question (forgot to copy the link).

RewriteEngine on
RewriteCond %{HTTP_HOST} ^*
RewriteRule .* http://192.168.x.x/ [P,L]

This works insomuch as it does redirect to the Mini's front page. But of course, so does every subsequent link click on the Mini page. I think I understand why it's doing it (anything that starts with gets directed to what is essentially the front page of the wiki server, and since subsequent links on the wiki server also include, it always ends up in the same place)

I just don't know what to do different. To be perfectly honest, I don't actually understand the syntax of those Rewrite lines.

I've seen countless examples of config entries and tried some of them, but without really understanding the syntax, it's kind of shooting in the dark.

This was a useful post, and after reading this question, I tried adding this to my /apache2/httpd.conf file

<Location />
   ProxyPass http://192.168.x.x
   ProxyPassReverse http://192.168.x.x

No luck.

Clearly, I have some learning to do, but it would seem to me that what I want to do is probably quite simple. What am I missing?


My /etc/apache2/httpd.conf file

ServerName localhost

<VirtualHost *:80>
   DocumentRoot /var/www/domain

<VirtualHost *:80>
   DocumentRoot /var/www/mysub
   <Location />
      ProxyPass http://192.168.x.x/
      ProxyPassReverse http://192.168.x.x/

... and my sites-available/mysub file...

<VirtualHost *:80>
        DocumentRoot /var/www/mysub

        #ProxyRequests Off
        <Location />
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        <Directory /var/www/mysub>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all

        ErrorLog /var/log/www/mysub/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog /var/log/apache2/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from ::1/128

Output of apache2ctl -S

VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80                   is a NameVirtualHost
         default server (/etc/apache2/sites-enabled/000-default:1)
         port 80 namevhost (/etc/apache2/sites-enabled/000-default:1)
         port 80 namevhost (/etc/apache2/sites-enabled/domain:1)
         port 80 namevhost (/etc/apache2/sites-enabled/mysub:1)
Syntax OK
share|improve this question
Nice first question :-). – Tom Marthenal Aug 1 '12 at 3:31
@TomMarthenal Cheers! – JoshP Aug 1 '12 at 4:46
up vote 2 down vote accepted

You're very close!

A couple notes:

  • RewriteCond %{HTTP_HOST} ^* - The HTTP_HOST variable only contains, not the rest of the path.

    This rule actually matches, but accidentally - there's no / character there, but the * modifier applies to the / character, meaning "repeat the / 0 to infinite times".

    Apache uses perl-compatible regex - to match the exact host, it should look like this:

    RewriteCond %{HTTP_HOST} ^mysub\.domain\.com$
  • RewriteRule .* http://192.168.x.x/ [P,L] - This is only loading the home page since it's not including the rest of the passed path - this must be manually done when using the [P] flag of RewriteRule.

    This should work:

    RewriteRule (.*) http://192.168.x.x/$1 [P,L]
  • The ProxyPass setup is almost right, except it's being overridden by the setup in the .htaccess file, so it's not being used. Using .htaccess is bad for performance and potentially problematic for security - see the recommendation in the Apache documentation here.

    Probably the best approach is to delete the .htaccess file outright, and just use ProxyPass. Change your config a small bit...

    <Location />
       ProxyPass http://192.168.x.x/
       ProxyPassReverse http://192.168.x.x/

    ...and move it from your httpd.conf over to within the <VirtualHost> block that's serving the subdomain.

    With the matching trailing slashes and no more .htaccess, this should do the trick!

share|improve this answer
Thanks so much for the answer! I've axed the .htaccess file. I've altered the <Location> block with the trailing slashes. The URL still just directs me to the /var/www/mysub "It Works" page. One thing I may be doing wrong here... My <VirtualHost> block is IN my httpd.conf file. When you say to move it, is my <VirtualHost> block in the wrong place? – JoshP Aug 1 '12 at 2:29
@Josh The "typical" way to create a virtual host on an Ubuntu system is to create a file like /etc/apache2/sites-available/site-name then run a2ensite site-name to enable it (which creates a symlink in /etc/apache2/sites-enabled). It still works just fine in httpd.conf, though. Go ahead and move the <Location> block into the <VirtualHost> block and restart Apache. If that doesn't do the trick, can you provide the <VirtualHost> block, as well as the output from apache2ctl -S? (edit the extra info into your question as opposed to putting it in a comment, for formatting) – Shane Madden Aug 1 '12 at 2:35
I actually do have it created in sites-available and linked to -enabled. I'll post both in the question. Is it wrong to have the site defined in both places? – JoshP Aug 1 '12 at 2:47
@Josh You'll only want it defined in one location - that may be part of the problem. – Shane Madden Aug 1 '12 at 2:51
Ok, is it "typical" then, to have it all defined in the sites-available? Shall I remove the <VirtualHost> blocks in the httpd.conf file? Would that then leave only the ServerName localhost entry? – JoshP Aug 1 '12 at 3:05

This was the final piece of the puzzle. Found it as the answer over at this question.

The solution is to have this in /etc/apache2/mods-enabled/proxy.conf:

<IfModule mod_proxy.c>
ProxyRequests Off
<Proxy *>
  AddDefaultCharset off 
  Order deny,allow
  Allow from all 
share|improve this answer

Your Answer


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.