LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 02-04-2010, 07:55 PM   #1
ratcateme
Member
 
Registered: Feb 2008
Distribution: CentOS 5.4
Posts: 59

Rep: Reputation: 15
source address based virtual hosting


i have no idea where to ask this so i though i would start here.
i have a small home network with a linux box (CentOS 5.4, Apache 2.2.3)
currently all but www.mydomain.com/internet/ is blocked to everyone outside local lan by this config
Code:
<Location />
    Order deny,allow
    Deny from all
    Allow from 127.0.0.1
    Allow from 10.
</Location>
<Location /internet>
    Order allow,deny
    Allow from all
</Location>
allowing my local network 10.0.0.0/8
currently my router is setup to port forward 80 to 10.1.1.2 (address of the server)
and it works fine with people who browse to www.mydomain.com from the internet get a 403 and when going to www.mydomain.com/internet/ are allowed, and people on the local lan get allowed to both
i would like to have it setup with some kind of virtual hosting so that when people form the internet enter www.mydomain.com/ they get the page www.mydomain.com/internet/
while if i enter www.mydomain.com/ from my local lan they get the main directory.
i have no idea how to do this im not very familiar with the httpd config files.
 
Old 02-04-2010, 11:42 PM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
There are a couple of choices, my preferred option would be to make users on the lan use an internal domain name ( www.mydomain.int ) and use named vhosts
http://httpd.apache.org/docs/2.2/vhosts/name-based.html.

Another choice would be to add a sub-interface with an extra ip address and have internal users resolve www.mydomain.com only as the new address, then use standard ip based vhosts.

The third option is to use rewrite rules (mod_rewrite) based on the source addresses.

hth
 
Old 02-05-2010, 02:40 AM   #3
ratcateme
Member
 
Registered: Feb 2008
Distribution: CentOS 5.4
Posts: 59

Original Poster
Rep: Reputation: 15
tanks for the advise
i dont know if this is a bad thing but i kinda like you last option best. i had read a little about it earlier on today i understand mod_rewrite but i can't see where you apply the filtering.
could you give me some examples of how to apply filtering like that?

thanks
 
Old 02-05-2010, 05:44 AM   #4
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
Mod_rewrite is one of the trickiest things to get right if you're not using it regularly, the config below should be about the right structure but its completely untested:

Code:
RewriteEngine on
RewriteLog /var/log/httpd/mydomain_rewrite.log
RewriteLogLevel 9

RewriteCond %{REMOTE_ADDR} !^10.*
RewriteCond %{REQUEST_URI} !^/internet/ [NC]
RewriteRule ^/(.*)$ http://www.mydomain.com/internet/$1 [R=301,L]
Once you have it working, drop the rewrite log level down to reduce the log file size

hth
 
Old 02-05-2010, 04:07 PM   #5
ratcateme
Member
 
Registered: Feb 2008
Distribution: CentOS 5.4
Posts: 59

Original Poster
Rep: Reputation: 15
thanks for the help that worked perfectly no changes needed.
now i have to readup more on mod_rewrite so i can cahnge or update it when needed

thanks
scott.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
virtual name based hosting atomicrm Linux - Server 8 12-17-2009 09:20 AM
Iptables and Name-Based Virtual Hosting Yahooguntu Linux - Software 5 08-26-2009 07:27 PM
name based virtual hosting with two ips nephish Linux - Server 3 07-05-2007 07:29 AM
name based virtual hosting jkmartha Linux - Software 4 08-04-2005 09:21 AM
name based virtual hosting adm1329 Linux - Networking 5 05-05-2004 11:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 08:13 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration