Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Apache on Windows 8 Multiple Virtual Hosts on Same IP

Status
Not open for further replies.

PCHomepage

Programmer
Feb 24, 2009
609
US
I've always used individual IPs (127.0.0.1, 127.0.0.2, etc.) on my local development system and just realized that I can use the same for all although I cannot get it to work. It just gives a directory listing of the root (the browser is on the same system as the server).

In hosts I have something like:

Code:
127.0.0.1	localhost
127.0.0.1	site1
127.0.0.1	site2
127.0.0.1	site3

httpd.conf has in part:

Code:
ServerRoot "C:/Server/Apache"
Listen 80
DirectoryIndex index.php

Include "conf/extra/httpd-vhosts.conf"

httpd-vhosts.conf has in part:

Code:
NameVirtualHost *.80

<Directory C:/Server/Sites>
	Order Deny,Allow 
	Allow from all
</Directory>

<VirtualHost *:80>
DocumentRoot C:/Server/Sites
ServerName localhost
</VirtualHost>

<VirtualHost *:80>
DocumentRoot C:/Server/Sites/site1
ServerName site1
ServerAlias site1
</VirtualHost>

<VirtualHost *:80>
DocumentRoot C:/Server/Sites/site2
ServerName site2
ServerAlias site2
</VirtualHost>

<VirtualHost *:80>
DocumentRoot C:/Server/Sites/site3
ServerName site3
ServerAlias site3
</VirtualHost>

Although I didn't reboot the system I did restart Apache after any changes. What am I missing?



 
have tried setting the hostnames as a fully qualified domain path using a non-existent tld?

.lcl, .local, or similar?


Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Although you can you use the same IP for multiple sites you can have only one 'listening' on port 80. You would have to use host headers or alter your config to use different ports ex) Site2
 
Yes, after posting I added a .dev to each but still no difference. I also rebooted just in case it was necessary as some blogs seemed to think it was but it made no difference.
 
If it takes different ports for each (no online blogs indicated that), it would be better for me to use individual IPs as it was originally. No problem doing it but it's a bit messier and seems unnecessary but apparently it is!
 
You can use Virtual Hosts, different IPs or different ports or any combination of the three for running multiple site on Apache.

The * in
Code:
NameVirtualHost *.80
means "All IPs"

I also rebooted just in case it was necessary as some blogs seemed to think it was but it made no difference.

No but you do need to restart Apache each time you make a change so it reloads httpd.conf.

Have you added the VirtualHosts to httpd.conf directly rather than the included config file?

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
I had the VirtualHosts, each with its own IP, in the httpd.con file originally but I prefer to move it to httpd-vhosts.conf for easy of maintenance which is what I am currently trying to do. As I stated, I have been restarting Apache after each change but since nothing was changing, I tried the reboot, which I needed to do anyway after uninstalling an application.
 
you must make sure that your dns knows what each of these domains means. and they should be properly qualified too.

so use something like

Code:
<VirtualHost *:80>
DocumentRoot C:/Server/Sites/site3
ServerName site3.local
</VirtualHost>

then either update your local dns or add a line to hosts

Code:
127.0.0.1	site3.local

then flush the dns and restart apache
Code:
ipconfig /flushdns
httpd.exe -k restart -n "MyServiceName"
 
Already did all that. Still only a directory listing.
 
For the moment, I moved back to individual IPs for each site and can load them only by their IP. Using the VirtualHosts name still gives only the folder listing. Since this is a development system only, it is good enough for now.
 
unless you have provided a Directory Index directive, a directory listing is what you would expect.

Code:
<VirtualHost *:80>
DocumentRoot C:/Server/Sites/site3
ServerName site3.local
<Directory "C:/Server/Sites/site3">
 DirectoryIndex index.php index.html index.htm
</Directory>
</VirtualHost>
 
See my original posting where the Directory is specified:

Code:
<Directory C:/Server/Sites>
	Order Deny,Allow 
	Allow from all
</Directory>

According to everything I've read online it is valid so to it independently of the VistualHosts directives if they are all in the same location, as they are.

However, even with everything specified exactly as you indicated (changed to suit, of course) still gives only the folder listing. Unless I specify the IP (127.0.0.2:80 now) and load the IP into the browser it also gives only the folder listing.

It's as though the httpd-vhosts.conf file is being ignored but it isn't as purposely entering something bogus causes Apache to fail. I am running Windows 8 and I understand that this version might have issues with httpd-vhosts.conf but I am not sure of the workaround.
 
is the directory listing:
a. the standard apache listing type
b. listing the intended directory (i.e. the server root for the relevant virtual host)

if so, try clicking on a php file. is it served as parsed php or as text?

are there any errors in your apache logs or system logs?

if you expressly force a test of your apache config what do you get?
Code:
 apachectl -t  // on linux - no idea what the equivalent is on windows

have you double checked the dns entry?

Code:
nslookup
> nameofdomain

...
Name: nameofdomain
Address: 127.0.0.1
 
The list is of the server root where it should be. The sub-folders within it contain the individual sites. The local domain names are all correct. That is, they match between hosts and httpd-vhosts.conf just as they should. I know that Linux uses multiple files for virtual hosts, one for each domain, but Windows generally does it either in the httpd.conf or, as this case, in the httpd-vhosts.conf, file. I don't know if there is a Windows equivalent for apachectl or how to run it if there is. PHP files appear to be parsed properly.

I am not a stranger to Apache but have never had this problem before although it's also the first time I've used the httpd-vhosts.conf file to configure sites.
 
then it seems like everything is working as it should do for virtual hosts, except the directory index directive

this must be a parsing error thus something wrong in where you have put the directory index directives or mistyping them etc.

if you were to post your entire (unedited) httpd.conf and vhosts.conf it would be easy to verify this.

the configtest in windows ( according to google ) is
Code:
httpd.exe -t

 
good. that means that there are no parse errors. but that does not mean that the configs are being parsed the way you think they ought to be.

for that we will need to see the entirety of the config files and all linked files.

or strip back your config to the bare minimum for a traditional server and install a GUI or other admin tool to manage the configuration files for you; then compare the results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top