Multiple Virtual Sites with Wampserver

2019-09-04 09:21发布

问题:

I've having a problem creating multiple virtual hosts, I've edit C:\wamp\alias\web.local to look like this:

NameVirtualHost *:80
<VirtualHost *:80>
    ServerAdmin webmaster@website1.local           
    DocumentRoot "C:/Documents and Settings/username/workspace/www.website1.com"
    ServerName website1.local

    <Directory "C:/Documents and Settings/username/workspace/www.website1.com">
            DirectoryIndex index.php index.htm index.html
            Options Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
            AllowOverride All
            Order allow,deny
            Allow from all
    </Directory>
</VirtualHost>

NameVirtualHost *:80
<VirtualHost *:80>
    ServerAdmin webmaster@website2.local           
    DocumentRoot "C:/Documents and Settings/username/workspace/www.website2.com"
    ServerName website2.local

    <Directory "C:/Documents and Settings/username/workspace/www.website2.com">
            DirectoryIndex index.php index.htm index.html
            Options Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
            AllowOverride All
            Order allow,deny
            Allow from all
    </Directory>
</VirtualHost>

NameVirtualHost *:80
<VirtualHost *:80>
    ServerAdmin webmaster@website3.local           
    DocumentRoot "C:/Documents and Settings/username/workspace/www.website3.com"
    ServerName website3.local

    <Directory "C:/Documents and Settings/username/workspace/www.website3.com">
            DirectoryIndex index.php index.htm index.html
            Options Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
            AllowOverride All
            Order allow,deny
            Allow from all
    </Directory>
</VirtualHost>

NameVirtualHost *:80
<VirtualHost *:80>
    ServerAdmin webmaster@website4.local           
    DocumentRoot "C:/Documents and Settings/username/workspace/www.website4.com"
    ServerName website4.local

    <Directory "C:/Documents and Settings/username/workspace/www.website4.com">
            DirectoryIndex index.php index.htm index.html
            Options Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
            AllowOverride All
            Order allow,deny
            Allow from all
    </Directory>
</VirtualHost>

and my hosts file looks like this:

127.0.0.1       localhost
127.0.0.1       website1.local
127.0.0.1       website2.local
127.0.0.1       website3.local
127.0.0.1       website4.local

I've restarted Wampserver but I don't seem to be able to access website1.local, website2.local, website3.local or website4.local. I get a 'Network Error (dns_unresolved_hostname)' error message.

Please note localhost is the only one that seems to work.

Any help appreciated.

Regards, Stephen

EDIT

I'm running Wampserver 2.2 on Windows XP.

回答1:

Couple of problems, You dont create virtual hosts by editing that file.

You use this file c:\wamp\bin\apache\apache.2.x.y\conf\extra\httpd-vhosts.conf then you uncomment the 'Include conf/extra/chris-vhosts.conf' from within the https.conf file, its near the bottom of the file.

Now the VHOST definitions you quote above look pretty good so you can probably just move then to the correct place and you a pretty good to go.

Except for

Is is a Very Very bad idea to use directory structures that contain spaces eg

DocumentRoot "C:/Documents and Settings/username/workspace/www.website3.com"

It is much safer to place your site code in a structure something like this

C:\websites\www\website3
C:\websites\www\website4

or even

D:\websites\www\website4

Oh and one more thing, you only need one reference to

NameVirtualHost *:80

Normally the first line of the vhost definition file.