4

Everything is working perfectly in my Windows 7.

The problem is when I add a domain1.com as VirtualHost, localhost's DocumentRoot changes to VirtualHost's DocumentRoot.

Eg: When I visit http://localhost, DocumentRoot which I specified for domain1.com is opened and not the one specified in httpd.conf.

My httpd-vhosts.conf file is:

NameVirtualHost 127.0.0.1:80
NameVirtualHost domain1.com:80
<VirtualHost domain1.com:80>
<Directory "e:/program files/apache/htdocs/domain1.com">
    Options FollowSymLinks Indexes
    AllowOverride All
    Order deny,allow
    allow from All
</Directory>
ServerName domain1.com
ServerAlias domain1.com
ScriptAlias /cgi-bin/ "e:/program files/apache/htdocs/domain1.com/cgi-bin/"
DocumentRoot "e:/program files/apache/htdocs/domain1.com"
ErrorLog "E:/Program Files/apache/logs/domain1.com.err"
CustomLog "E:/Program Files/apache/logs/domain1.com.log" combined
</VirtualHost>

My Hosts file :

127.0.0.1   domain1.com

My httpd.conf file :

DocumentRoot "e:/program files/apache/htdocs"
<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>
<Directory "e:/program files/apache/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

I know one solution is to add VirtualHost with ServerName as 127.0.0.1 or localhost but I am avoiding that.

Can I make localhost's DocumentRoot specified in httpd.conf a default one ?

Please let me know if you need additional information.

Thanks, Jigar.

Jigar D
  • 83
  • 1
  • 2
  • 5

1 Answers1

9

as stated in https://httpd.apache.org/docs/2.2/vhosts/name-based.html

"If you are adding virtual hosts to an existing web server, you must also create a <VirtualHost> block for the existing host. The ServerName and DocumentRoot included in this virtual host should be the same as the global ServerName and DocumentRoot. List this virtual host first in the configuration file so that it will act as the default host."

altmas5
  • 157
  • 6
Herokiller
  • 2,560
  • 5
  • 29
  • 48
  • "The `DocumentRoot` included in this virtual host should be the same as the global `DocumentRoot`". This is NOT TRUE. It all depends on your configuration. If you set `Options Indexes FollowSymlinks` for instance, you can set any directory inside the global `DocumentRoot` as the vhost's `DocumentRoot`. – Atralb Jan 21 '21 at 09:46