×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Apache on Windows 8 Multiple Virtual Hosts on Same IP

Apache on Windows 8 Multiple Virtual Hosts on Same IP

Apache on Windows 8 Multiple Virtual Hosts on Same IP

(OP)
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?



RE: Apache on Windows 8 Multiple Virtual Hosts on Same IP

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

RE: Apache on Windows 8 Multiple Virtual Hosts on Same IP

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 http://127.0.0.1:81

RE: Apache on Windows 8 Multiple Virtual Hosts on Same IP

(OP)
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.

RE: Apache on Windows 8 Multiple Virtual Hosts on Same IP

(OP)
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!

RE: Apache on Windows 8 Multiple Virtual Hosts on Same IP

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"

Quote:

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

RE: Apache on Windows 8 Multiple Virtual Hosts on Same IP

(OP)
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.

RE: Apache on Windows 8 Multiple Virtual Hosts on Same IP

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" 

RE: Apache on Windows 8 Multiple Virtual Hosts on Same IP

(OP)
Already did all that. Still only a directory listing.

RE: Apache on Windows 8 Multiple Virtual Hosts on Same IP

(OP)
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.

RE: Apache on Windows 8 Multiple Virtual Hosts on Same IP

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> 

RE: Apache on Windows 8 Multiple Virtual Hosts on Same IP

(OP)
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.

RE: Apache on Windows 8 Multiple Virtual Hosts on Same IP

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 

RE: Apache on Windows 8 Multiple Virtual Hosts on Same IP

(OP)
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.

RE: Apache on Windows 8 Multiple Virtual Hosts on Same IP

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 

RE: Apache on Windows 8 Multiple Virtual Hosts on Same IP

(OP)
Hmmm. Running httpd.exe -t says only:

Quote:

Syntax OK

so no clues there.

RE: Apache on Windows 8 Multiple Virtual Hosts on Same IP

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close