Page 1 of 1

Apache Virtualhost Question

Posted: Thu Oct 12, 2006 2:52 pm
by SpecialK
I have a conf file on an old server that was serving webpages. We are moving the pages to PHP from static HTML on a Linux server. The problem is we still have years of database data that is built from old IBM code.

I have ways to grab data from the server internally which is no problem. The problem is the CONF file has multiple entries for different hosts. Here is a trimmed down version with lots of Directory and Location stuff missing.

Code: Select all

<VirtualHost x.x.x.x:80>
   ServerName www.myaddress1.com
   ServerAlias myaddress1.com
   DocumentRoot /host1/
ErrorLog logs/host1
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" extended
LogFormat "%{Referer}i -> %U" referer
LogFormat %{User-agent}i agent


<Directory />
   Order Allow,Deny
   Deny From all
   UserID %%SERVER%%
</Directory>

</VirtualHost>
Now I must grab the file with PHP using the internal network: 192.x.x.x (from myaddress1.com) which is fine for the first entry. If I need to do it to an alternate entry (ex. myaddress2.com) from the same internal IP, it breaks because it doesn't use a server alias and seems to direct to the first entry.

My theories (having never setup any multiple apache server) is that I thought about having a blank server alias as the first entry so if I called 192.x.x.x it would default to there, but it wouldn't be able to be seen by any external users. What about using the actual number as the server alias?

Any help here, or places I should look for more information regarding this?

Sorry if I didn't fully explain myself here, I will add more information if it's needed.

Posted: Thu Oct 12, 2006 4:42 pm
by cinac
Is there a reason you can't add the ServerAlias directives for all the domains?

Posted: Thu Oct 12, 2006 4:45 pm
by cinac
If you do an IP-based access, Apache will always only return the first physical virtualhost entry in the config file. There's not a good way around that.

Do you need to do IP-based access or can you use the hostnames like external users would?? Your internal DNS server should be able to resolve the domain names to your internal IP scheme, while your external DNS server would give public users the corresponding public IPs. That way all your code can use domain names and get away from hard-coded "magic number" IP addresses which could change over time...

Posted: Fri Oct 13, 2006 4:43 am
by ibbo
Use name based virtual hosting.

make sure your hosts are all pointed to inside your hosts file. /etc/hosts

192.168.1.100 server.ncg.com images.ncg.com localdev.nationalclubgolfer.com

Code: Select all

#
# Use name-based virtual hosting.
#

NameVirtualHost 192.168.1.100:80

<VirtualHost images.ncg.com:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /home/images/public_html
    ServerName images.ncg.com
    ErrorLog logs/images.ncg.com-error_log
    CustomLog logs/images.ncg.com common
</VirtualHost>

<VirtualHost localdev.nationalclubgolfer.com:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /home/webuser/public_html
    ServerName localdev.nationalclubgolfer.com
    ErrorLog logs/localdev.nationalclubgolfer.com-error_log
    CustomLog logs/localdev.nationalclubgolfer.com-access_log common
</VirtualHost>

<VirtualHost server.ncg.com:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /home/intranet/public_html
    ServerName server.ncg.com
    ErrorLog logs/server.ncg.com-error_log
    CustomLog logs/server.ncg.com common
</VirtualHost>
You should then be able to access the sites by hostname http://server.ncg.com etc.

ibbo

Posted: Fri Oct 13, 2006 4:40 pm
by timvw
ibbo wrote: NameVirtualHost 192.168.1.100:80
I prefer to use NameVirtualHost *:80 (even more power ;))

(Ah well, if you search hard enough you'll find my httpd.conf in this forum somewhere....