| Author |  | 
| ehoelker 
 
 
 Joined: 02 Nov 2011
 Posts: 8
 
 
 | 
|  Posted: Wed 02 Nov '11 18:19    Post subject: Yet another virtual hosting problem <SOLVED> |   |  
| 
 |  
| I had a few small websites on a very old box in the basement and it crashed. I am in the process of reinstalling but have run into a problem with name-based virtual hosting. 
 I have successfully installed Apache 2.2.21 with PhP 5.2.17 and MySQL 5.5. I tested the installation successfully by using PhP to insert and then display records in a table.
 
 So it cam time for me to setup the virtual hosts. I run a number of subdomains on the main domain and one other domain. I read a number of suggestions on how to set up the vhosts file and have tried a number of different methods from very short virtual host directives to very long.
 
 Problem:
 I can go to www.site1.com and get the site1/index.php page. When I go to www.site2.com I get the site1/index.php. If I call www.site2.com/index.php I get the site2/index.php.
 
 virtual host containers:
 
  	  | Code: |  	  | <VirtualHost *> ServerName www.site1.com
 ServerAlias site1.com www.site1.com
 DocumentRoot "E:/webdocs/site1"
 <Directory "e:/webdocs/site1">
 Options Indexes FollowSymLinks MultiViews
 AllowOverride All
 Order allow,deny
 Allow from all
 </Directory>
 ErrorLog e:/webdocs/logs/site1.error.log
 CustomLog e:/webdocs/logs/site1.access.log common
 DirectoryIndex index.php index.html index.htm
 </VirtualHost>
 
 <VirtualHost *>
 ServerName www.site2.com
 ServerAlias site2.com www.site2.com
 DocumentRoot "E:/webdocs/site2"
 <Directory "e:/webdocs/site2">
 Options Indexes FollowSymLinks MultiViews
 AllowOverride All
 Order allow,deny
 Allow from all
 </Directory>
 ErrorLog e:/webdocs/site2.error.log
 CustomLog e:/webdocs/site2.access.log common
 DirectoryIndex index.php index.html index.htm
 </VirtualHost>
 | 
 In addition I have Listen 80 (in httpd.conf) and NameVirtualHost * (in httpd-vhosts.conf)
 
 I feel like I am missing something very basic and I would appreciate any help you could provide.
 
 Last edited by ehoelker on Wed 02 Nov '11 22:28; edited 1 time in total
 |  | 
| Back to top |  | 
| Steffen Moderator
 
 
 Joined: 15 Oct 2005
 Posts: 3131
 Location: Hilversum, NL, EU
 
 | 
|  Posted: Wed 02 Nov '11 19:00    Post subject: |   |  
| 
 |  
| The www.siteX.com in the ServerAlias should not be there. 
 Also make an extra virtual host as first one, the default. For example:
 
 <VirtualHost *>
 ServerName localhost
 ServerAlias 127.0.0.1
 ServerAlias your external IP for instance
 DocumentRoot C:/.../Apache2.2/htdocs
 </VirtualHost>
 
 This first VirtualHost section is used for all requests that do not match a ServerName or ServerAlias in any <VirtualHost> block.
 
 
 
 Steffen
 |  | 
| Back to top |  | 
| ehoelker 
 
 
 Joined: 02 Nov 2011
 Posts: 8
 
 
 | 
|  Posted: Wed 02 Nov '11 19:22    Post subject: |   |  
| 
 |  
| 1. I removed the offending entry from both ServerAlias. 
 2. I added the virtual host you suggested except for the external IP, I use a dynamic IP adress:
 <VirtualHost *>
 ServerName localhost
 ServerAlias 127.0.0.1
 DocumentRoot "E:/webdocs"
 </VirtualHost>
 
 Problem remains the same
 
 www.site1.com = webdocs/site1/index.php
 www.site2.com = webdocs/site1/index.php
 www.site2.com/index.php = webdocs/site2/index.php
 IP Address = webdocs/index.php
 |  | 
| Back to top |  | 
| Steffen Moderator
 
 
 Joined: 15 Oct 2005
 Posts: 3131
 Location: Hilversum, NL, EU
 
 | 
|  Posted: Wed 02 Nov '11 19:32    Post subject: |   |  
| 
 |  
| Try to remove the lines:      DirectoryIndex index.php index.html index.htm 
 And put the line in the main config.
 
 Also remove the two blocks <Directory ...>.... </Directory>
 
 And define in the main conf:
 
 <Directory />
 Options  Indexes FollowSymLinks MultiViews
 AllowOverride All (sure you want All here ?)
 Order allow,deny
 Allow from all
 </Directory>
 
 Steffen
 |  | 
| Back to top |  | 
| ehoelker 
 
 
 Joined: 02 Nov 2011
 Posts: 8
 
 
 | 
|  Posted: Wed 02 Nov '11 20:17    Post subject: |   |  
| 
 |  
| 1. I have removed the directoryindex and placed it into the main httpd.conf file. 
 
  	  | Code: |  	  | DirectoryIndex index.php index.html index.htm | 
 2. removed the directory containers from the virtual hosts in the vhosts config file and made a general entry in the main httpd.conf file.
 
  	  | Code: |  	  | <Directory /> Options Indexes FollowSymLinks Multiviews
 AllowOverride All
 Order allow,deny
 Allow from all
 </Directory>
 | 
 3. Here is the vhost now. Just so we are all on the same page:
 
 
  	  | Code: |  	  | <VirtualHost *> ServerName localhost
 ServerAlias 127.0.0.1
 DocumentRoot "E:/webdocs"
 </VirtualHost>
 
 <VirtualHost *>
 ServerName www.site1.com
 ServerAlias site1.com
 DocumentRoot "E:/webdocs/site1"
 ErrorLog e:/webdocs/logs/site1.error.log
 CustomLog e:/webdocs/logs/site1.access.log common
 </VirtualHost>
 
 <VirtualHost *>
 ServerName www.site2.com
 ServerAlias site2.com
 DocumentRoot "E:/webdocs/site2"
 ErrorLog e:/webdocs/logs/site2.error.log
 CustomLog e:/webdocs/logs/site2.access.log common
 </VirtualHost>
 | 
 Problem remains as described above.
 |  | 
| Back to top |  | 
| Steffen Moderator
 
 
 Joined: 15 Oct 2005
 Posts: 3131
 Location: Hilversum, NL, EU
 
 | 
|  Posted: Wed 02 Nov '11 20:41    Post subject: |   |  
| 
 |  
| I am puzzled. 
 Try it with a plain .html file.
 
 Is there some about siteX in C:\Windows\System32\drivers\etc\hosts ?
 
 Or leftovers of siteX in the main conf or htaccess (because you have All) ?
 
 Remove the Quotes (") in DocumentRoot.
 
 
 Steffen
 |  | 
| Back to top |  | 
| ehoelker 
 
 
 Joined: 02 Nov 2011
 Posts: 8
 
 
 | 
|  Posted: Wed 02 Nov '11 21:57    Post subject: |   |  
| 
 |  
| Thank you for all your help so far, I know we will get to mark this <solved> before it is all over. 
 1. I removed the quotes from DocumentRoot. Should I have quotes at all? Do some directives require quotes and some do not? Should I remove all quotes from the httpd.conf file?
 
 2. c:\windows\system32\drivers\etc\hosts.txt contains
 
 Plus about 1,000 entries by Spybot 	  | Code: |  	  | 127.0.0.1 localhost 127.0.0.1 site1.com
 127.0.0.1 site2.com
 | 
 
 3. httpd.conf contains the following siteX references
 
 
 
 4. there are no .htaccess files. The directories are empty (exception: see below)
 
 5. I removed all files from /webdocs and subdirectories (except webdocs/logs.) There is now a simple structure of:
 
  	  | Code: |  	  | /webdocs /webdocs/site1
 /webdocs/site2
 /webdocs/logs
 | 
 In every directory I created an index.html containing:
 where XXXX is the directory name of the file (i.e. site1, site2, webdocs) 	  | Code: |  	  | <html><body><h1>XXXX</h1></body></html> | 
 
 Restarted Apache, problem still exists as described above.
 |  | 
| Back to top |  | 
| ehoelker 
 
 
 Joined: 02 Nov 2011
 Posts: 8
 
 
 | 
|  Posted: Wed 02 Nov '11 22:08    Post subject: |   |  
| 
 |  
| Seems the problem may be resolved. The correct index.html files are now being served. I will try it with PHP and see if it continues to operate correctly. |  | 
| Back to top |  | 
| Steffen Moderator
 
 
 Joined: 15 Oct 2005
 Posts: 3131
 Location: Hilversum, NL, EU
 
 | 
|  Posted: Wed 02 Nov '11 22:15    Post subject: |   |  
| 
 |  
| Since you do not use .htaccess, you can set     AllowOverride All to AllowOverride none, is speeding up. 
 You are saying hosts.txt, look in hosts (without .txt).
 
 Steffen
 |  | 
| Back to top |  | 
| ehoelker 
 
 
 Joined: 02 Nov 2011
 Posts: 8
 
 
 | 
|  Posted: Wed 02 Nov '11 22:23    Post subject: |   |  
| 
 |  
| The problem is resolved. Not sure what exactly fixed it. I removed the quotes in DoucumentRoot directives as discussed above. 
 For anyone finding this thread and having the same problem here is the final httpd-vhosts.conf:
 
 
  	  | Code: |  	  | NameVirtualHost * 
 <VirtualHost *>
 ServerName localhost
 ServerAlias 127.0.0.1
 DocumentRoot E:/webdocs
 </VirtualHost>
 
 <VirtualHost *>
 ServerName www.site1.com
 ServerAlias site1.com
 DocumentRoot E:/webdocs/site1
 ErrorLog e:/webdocs/logs/site1.error.log
 CustomLog e:/webdocs/logs/site1.access.log common
 </VirtualHost>
 
 <VirtualHost *>
 ServerName www.site2.com
 ServerAlias site2.com
 DocumentRoot E:/webdocs/site2
 ErrorLog e:/webdocs/logs/site2.error.log
 CustomLog e:/webdocs/logs/site2.access.log common
 </VirtualHost>
 
 | 
 final c:\windows\system32\drivers\etc\hosts:
 
  	  | Code: |  	  | 127.0.0.1 localhost 
 | 
 relevant lines form httpd.conf
 
  	  | Code: |  	  | Listen 80 ServerName www.site1.com:80
 DocumentRoot E:/webdocs/site1
 
 <Directory />
 Options FollowSymLinks
 AllowOverride None
 Order allow,deny
 Allow from all
 </Directory>
 
 DirectoryIndex index.php index.html index.htm
 
 Include conf/extra/httpd-vhosts.conf
 | 
 There is no Directory entries for either /webdocs, /webdocs/site1, or /webdocs/site2
 
 Last edited by ehoelker on Wed 02 Nov '11 22:37; edited 2 times in total
 |  | 
| Back to top |  | 
| Steffen Moderator
 
 
 Joined: 15 Oct 2005
 Posts: 3131
 Location: Hilversum, NL, EU
 
 | 
|  Posted: Wed 02 Nov '11 22:26    Post subject: |   |  
| 
 |  
| Thanks for sharing you conf in this way. 
 Steffen
 |  | 
| Back to top |  | 
| ehoelker 
 
 
 Joined: 02 Nov 2011
 Posts: 8
 
 
 | 
|  Posted: Wed 02 Nov '11 22:27    Post subject: |   |  
| 
 |  
| My choice would also be to remove indexes in general and enable Indexes on a directory by directory basis. Do you agree with that general assessment for security sake? |  | 
| Back to top |  | 
| Steffen Moderator
 
 
 Joined: 15 Oct 2005
 Posts: 3131
 Location: Hilversum, NL, EU
 
 | 
|  Posted: Wed 02 Nov '11 22:32    Post subject: |   |  
| 
 |  
| I should not use indexes when you not really use it. Also not sure why you have Multiviews
 
 So advised to use:
 
 Options  FollowSymLinks
 
 
 Steffen
 |  | 
| Back to top |  | 
| ehoelker 
 
 
 Joined: 02 Nov 2011
 Posts: 8
 
 
 | 
|  Posted: Wed 02 Nov '11 22:36    Post subject: |   |  
| 
 |  
| I appreciate your advice. I will change the above for posterity. |  | 
| Back to top |  |