LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 05-09-2002, 11:56 AM   #1
Syncrm
Member
 
Registered: Aug 2001
Location: Lansing, Michigan
Distribution: slackware8+
Posts: 472

Rep: Reputation: 30
Virtualhosts + firewall


hello all.
my problem is as follows: i have 3 domains, all hosted on the same linux box with apache. i recently configured a firewall on my network which runs slackware8 with iptables. my cable company blocks port 80, so i had been getting around that by having outside DNS servers point my domain from www.domain.com to web.domain.com:81. this works great, except for that my virtual hosts don't work.

however, they work perfectly from inside my network. if i use the IP of my linux machine (192.168.1.56) in the virtual hosts the it works fine, but from anywhere outside the network the virtual hosts don't appear to work... perhaps a firewall issue? does anyone have any suggestions?

i've tried putting both the whole domain name <VirtualHost web.domain.com:81> and the IP as well, neither work.

i appreciate the help!
 
Old 05-10-2002, 01:19 AM   #2
Token
LQ Newbie
 
Registered: May 2002
Location: Atlanta
Distribution: RH 7.2
Posts: 20

Rep: Reputation: 0
With IPTABLES you may want to try the following:

iptables -t nat -A PREROUTING -p TCP --dport 81 -j DNAT --to (ip of webserver):80

Basically this will take anything incoming on port 81 and send it to port 80


I think that command is correct, it's late and I don't feel like fiddling with it. But something along those lines should do ya up nicely.
 
Old 05-10-2002, 07:21 AM   #3
Syncrm
Member
 
Registered: Aug 2001
Location: Lansing, Michigan
Distribution: slackware8+
Posts: 472

Original Poster
Rep: Reputation: 30
well, that half worked... let me describe what i think the problem is.

i'm pretty sure that when my firewall forwards the request from port 81 to port 80 of my webserver, it's losing the "www.domain.com" part, and my webserver only sees a request for my internal IP (192.168.1.56). i can create virtual hosts based on my internal IP, but that doesn't go any good, as every domain - no matter the name - will always use that IP.

does anyone have any ideas? thanx. :-)

Last edited by Syncrm; 05-10-2002 at 07:46 AM.
 
Old 05-12-2002, 03:33 AM   #4
Jon-
Member
 
Registered: Dec 2001
Distribution: RH5.2/6.2/7.0/7.1/7.2/9/ES21/ES31
Posts: 91

Rep: Reputation: 15
Try setting the VirtualHost parameter using the IP, and then define the HostName parameter to define the host name. Also, use NameVirtualHost parameter

The web site name is sent in the http header, not the TCP header. So, if that request is making through your firewall/port forwarder and arriving at the web server (verify using a packet sniffer on the web server), then you can pretty much assume that Apache isn't configured correctly, assuming that DNS is correctly configured.

So, the quick fix is to define web.domain.com as well as www.domain.com and point them to the same www code base, and hope the code base doesn't have hardcoded server names anywhere.

However, it seems there is something wonky w/ the port change. The header arrives at Apache requesting port 81, even though you've configured that same server to be on port 80...

I'd change that port 81 in the virtualhost to port 80, since that's what's it's listening on. Apache should then match the servername directive to that provided in the http header (so you see the correct web site). Also, I'd set the NameVirtualHost parameter to the same iport parameter

Someone correct me if I'm wrong... I don't think I've actually tried this yet...

Last edited by Jon-; 05-12-2002 at 04:28 AM.
 
Old 05-14-2002, 09:52 AM   #5
Syncrm
Member
 
Registered: Aug 2001
Location: Lansing, Michigan
Distribution: slackware8+
Posts: 472

Original Poster
Rep: Reputation: 30
unfortunately, this still isn't working. i've defined my virtual hosts correctly, as far as i know. but they're still not working outside my firewall. it's really puzzling. but here are how my virtual hosts appear in my httpd.conf file:

<VirtualHost web.domain.com:81>
DocumentRoot /usr/local/apache/htdocs
ServerAdmin root@domain.com
ServerName toby.domain.com
ErrorLog logs/error_log
CustomLog logs/access_log custom
</VirtualHost>

<VirtualHost 192.168.1.56>
DocumentRoot /usr/local/apache/htdocs/internal
ServerAdmin root@toby
ServerName toby.lion
ErrorLog logs/internal/error_log
CustomLog logs/internal/access_log custom
</VirtualHost>

as you can see, any machine trying to access the IP 192.168.1.56 will be forwarded to a different document root, as i would like my internal clients to have unique data to load. however, the first virtual host entry does not work at all. i've changed it around to everything, even the IP and it still won't work. i'm open to suggestions. thanx :-)

Last edited by Syncrm; 05-14-2002 at 09:55 AM.
 
Old 05-14-2002, 05:41 PM   #6
Jon-
Member
 
Registered: Dec 2001
Distribution: RH5.2/6.2/7.0/7.1/7.2/9/ES21/ES31
Posts: 91

Rep: Reputation: 15
Don't forget the NameVirtualHost parameter. And, the VirtualHost parameter should be an IPort (which I'd match with the NameVirtualHost parameter).

And, the ServerName parameter needs to match the EXACT name of the server referenced, both internally and externally, which means it should probably be a FQDN.

So, you'll have

<NameVirtualHost 192.168.1.56:80>

<VirtualHost 192.168.1.56:80>
ServerName www.domain.com
DocumentRoot /usr/local/apache/htdocs
</VirtualHost>

<VirtualHost 192.168.1.56:80>
ServerName web.domain.com
DocumentRoot /usr/local/apache/htdocs
</VirtualHost>

With that, I'd hope that Apache can handle the rest (like matching the name in the http request header) with the port change.
 
Old 05-16-2002, 02:46 PM   #7
Syncrm
Member
 
Registered: Aug 2001
Location: Lansing, Michigan
Distribution: slackware8+
Posts: 472

Original Poster
Rep: Reputation: 30
i think, perhaps, you're running a different build of apache than i am. when i add the NameVirtualHost line, i get errors returned when i restart apache; something to the effect of not being defined.

virtual hosts have always worked prior to my firewall, which leads me to believe it has something to do with that.

all help is appreciated! :-)
 
Old 05-18-2002, 11:27 AM   #8
Jon-
Member
 
Registered: Dec 2001
Distribution: RH5.2/6.2/7.0/7.1/7.2/9/ES21/ES31
Posts: 91

Rep: Reputation: 15
Prior to your firewall you didn't have multiple named virtual hosts, so there was just one site to worry about. Now you have several, and they don't have a common IP/port.

AFAIK, this feature has been available in 1.3.x for quite some time now. And, it's also in 2.x. So, unless you're using a version from MANY years ago (like 1.2.x), it should work. If you are running 1.2, it's WAY past time to upgrade There have been numerous security fixes since then. Which version are you running? You can look at the error_log when you restart Apache to determine this.

Also, what is the exact error you receive?

Last edited by Jon-; 05-19-2002 at 03:13 AM.
 
Old 05-21-2002, 07:23 AM   #9
Syncrm
Member
 
Registered: Aug 2001
Location: Lansing, Michigan
Distribution: slackware8+
Posts: 472

Original Poster
Rep: Reputation: 30
well, i figured out why i was receiving an error. you aren't supposed to put the <>s around the NameVirtualHost. this is how it appears in my httpd.conf file:

NameVirtualHost *

<VirtualHost web.domain.net:81>
DocumentRoot /usr/local/apache/htdocs/internal
ServerAdmin root@domain.net
ServerName toby.domain.net
ErrorLog logs/error_log
CustomLog logs/access_log custom
</VirtualHost>

<VirtualHost 192.168.1.56>
DocumentRoot /usr/local/apache/htdocs
ServerAdmin root@toby
ServerName toby.lion
ErrorLog logs/internal/error_log
CustomLog logs/internal/access_log custom
</VirtualHost>

however, this still is not working. but i do really appreciate your help thus far, jon. :-)

Last edited by Syncrm; 05-21-2002 at 07:25 AM.
 
Old 05-21-2002, 10:42 AM   #10
Jon-
Member
 
Registered: Dec 2001
Distribution: RH5.2/6.2/7.0/7.1/7.2/9/ES21/ES31
Posts: 91

Rep: Reputation: 15
Oh geez... my bad, sorry...

So, the ultimate goal of this is to make sure the web server (IP) is accessible by different names. So, the server names will be different but the IPs are the same (internally).

Anyway, your file should probably look something like this:

NameVirtualHost 192.168.1.56:80

<VirtualHost 192.168.1.56:80>
DocumentRoot /usr/local/apache/htdocs
ServerAdmin root@domain.net
ServerName toby.domain.net
ErrorLog logs/error_log
CustomLog logs/access_log custom
</VirtualHost>

<VirtualHost 192.168.1.56:80>
DocumentRoot /usr/local/apache/htdocs/internal
ServerAdmin root@toby
ServerName toby.lion
ErrorLog logs/internal/error_log
CustomLog logs/internal/access_log custom
</VirtualHost>

This will allow you to build two sites internally, and put it on 192.168.1.56:80, but have the server accessible by both toby.lion, and toby.domain.net -- one being the internal name and one being the external name. I'm hoping (guessing that Apache will know to strip off the port stuff when it's attempting to match the name entered in the http header to the ServerName tag. If not, I guess you could append the port to the servername, but I'm not sure if that'll work or not. So, in other words, if

toby.domain.net:81 is the way to access the internal site via the external Internet, then changing the ServerName tag to be

ServerName toby.domain.net:81

and leaving everything else the same might just fix things.

Incidentally, you have somewhat of a security flaw w/ this layout. It's now possible for the external site to access the internal code (toby.domain.net/internal). It would be better to reverse this (who cares if the internal site can access the external code). So, have /usr/local/apache/htdocs for the internal site and /usr/local/apache/htdocs/external for the external site.
 
  


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
Apache VirtualHosts Problem stratisphere Linux - Newbie 4 11-27-2004 12:20 AM
NameVirtualHost IP# has no VirtualHosts? DigiCrime Linux - Networking 2 10-11-2004 12:24 AM
VirtualHosts amdathlonboy Linux - Networking 6 06-21-2004 01:59 PM
Adding multiple VirtualHosts ecroswell Linux - Networking 3 03-14-2003 07:26 AM
Squirrelmail and VirtualHosts micaheli Linux - Networking 6 12-27-2002 01:00 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 12:49 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