Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I would like to have local (intranet) HTTP traffic go to the /var/www/html folder while any public traffic goes to the subfolder, /var/www/html/public

I've tried this configuration, with some variation, in httpd.conf

<VirtualHost PRIVATE-IP>
    DocumentRoot /var/www/html
    ServerName ecn
    ErrorLog /var/www/logs/error/private
    CustomLog /var/www/logs/access/private common
</VirtualHost>

<VirtualHost PUBLIC-IP>
    DocumentRoot /var/www/html/public
    ServerName PUBLIC-DOMAIN-NAME
    ErrorLog /var/www/logs/error/public
    CustomLog /var/www/logs/access/public common
</VirtualHost>

PUBLIC-IP, PRIVATE-IP, and PUBLIC-DOMAIN name are all replaced with the correct values in the actual document.

The problem is, local traffic can browse fine but remote traffic is directed to the root folder and getting 403d (because I have that folder blocked off through my .htaccess file). If I append /public to the URL it works fine.

share|improve this question
    
What's in your public error log? When you browse publicly do you see hits to your public access and error log? –  jeffatrackaid Sep 3 at 19:01

2 Answers 2

I am not aware of the solution you are using but it does look solid from here. Clearly I have something new to learn.

I do redirects depending upon IP addresses in .htaccess. I thought I would provide an example if it helps.

RewriteCond %{REMOTE_ADDR} "!^120.0.0.([0-255])$"
RewriteRule mydomain.com/public [R,L]

If this is not right, perhaps it is enough to get you there. You can use it in the httpd.conf or .htaccess files and modify it to your purposes. If your private IP address is not this simple, let me know. I have more complex examples.

share|improve this answer

Check that you are using NameVirtualHost directive for each IP address. From the documentation, that is required.

Your first Virtual host is the "default" virtual host. I think that your public virtual host isn't actually matching anything and is getting caught in the first "default" virtual host. I would create a "dummy" virtual host that goes first. Try this:

Listen 80

# public
NameVirtualHost 11.22.33.44:80
# private
NameVirtualHost 192.268.0.1:80

<VirtualHost _default_:*>
    # Default virtual host configuration 
    DocumentRoot /var/www/html/default
    ServerName default
    ErrorLog /var/www/logs/error/default
    CustomLog /var/www/logs/access/default common
</VirtualHost>

<VirtualHost 192.168.0.1:80>
    DocumentRoot /var/www/html
    ServerName ecn
    ErrorLog /var/www/logs/error/private
    CustomLog /var/www/logs/access/private common
</VirtualHost>

<VirtualHost 11.22.33.44:80>
    DocumentRoot /var/www/html/public
    ServerName www.example.com
    ErrorLog /var/www/logs/error/public
    CustomLog /var/www/logs/access/public common
</VirtualHost>
share|improve this answer
1  
NameVirtualHost should only be required if more than one host was defined on the IP. –  jeffatrackaid Sep 3 at 19:09

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.