简体   繁体   中英

Apache virtual-host not working correctly for subdomain

I've got a site set up on localhost that I'm actively developing, and I'd like to set up a subdomain on localhost to make my life 10* easier.

I added this to C:\\xampp\\apache\\conf\\extra\\httpd-vhosts.conf :

<VirtualHost i1.localhost:80>
    ServerAdmin dummy@localhost
    DocumentRoot "C:/xampp/htdocs/i1/"
    ServerName i1.localhost
    ServerAlias www.i1.localhost
    ErrorLog "logs/dummy-host2.localhost-error.log"
    CustomLog "logs/dummy-host2.localhost-access.log" combined
</VirtualHost>

Apache stats up fine, but when I navigate to http://localhost/ I'm seeing content from the i1 subdomain. http://i1.localhost/ works fine, however.

Then I tried doing this:

<VirtualHost localhost:80>
    ServerAdmin dummy@localhost
    DocumentRoot "C:/xampp/htdocs/"
    ServerName localhost
    ServerAlias www.localhost
    ErrorLog "logs/dummy-host2.localhost-error.log"
    CustomLog "logs/dummy-host2.localhost-access.log" combined
</VirtualHost>

<VirtualHost i1.localhost:80>
    ServerAdmin dummy@localhost
    DocumentRoot "C:/xampp/htdocs/i1/"
    ServerName i1.localhost
    ServerAlias www.i1.localhost
    ErrorLog "logs/dummy-host2.localhost-error.log"
    CustomLog "logs/dummy-host2.localhost-access.log" combined
</VirtualHost>

But that worked the opposite. On both localhost and i1.localhost I'm seeing content from C:/xampp/htdocs/ .

Anyone got an idea what's going wrong?

Cheers.

Apache usually does not like a vhosts document root inside another vhost, try:

DocumentRoot "C:/xampp/htdocs/"

and

DocumentRoot "C:/xampp/i1/"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM