For example, there are two domain names: www. linuxidc and www.linuxidc.net.
Create files a and B in the/etc/apache2/sites-available Directory, you can see that there will also be a file connection (just a soft connection) under the sites-enabled file to the corresponding file under the sites-available file.
To facilitate management, a name is also easy to remember.
Edit the content of the file as follows:
NameVirtualHost www. linuxidc
<VirtualHost www. linuxidc>
ServerName www. linuxidc
ServerAlias linuxidc *. linuxidc
ServerAdmin webmaster @ linuxidc
DocumentRoot/var/www//
<Directory/>
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory/var/www/a/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow, deny
Allow from all
# This directive allows us to have apache2s default start page
# In/apache2-default/, but still have/go to the right place
# Commented out for Ubuntu
# RedirectMatch ^/$/apache2-default/
</Directory>
ScriptAlias/cgi-bin // usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options ExecCGI-MultiViews + SymLinksIfOwnerMatch
Order allow, deny
Allow from all
</Directory>
ErrorLog/var/log/apache2/a. log
# Possible values include: debug, info, notice, warn, error, crit,
# Alert, emerg.
LogLevel warn
CustomLog/var/log/apache2/access. log combined
ServerSignature On
Alias/doc/"/usr/share/doc /"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny, allow
Deny from all
Allow from 127.0.0.0/255.0.0.0: 1/128
</Directory>
</VirtualHost>
The content in file B is basically the same as that in file a. You only need to change the content in a few places.
Run the a2ensite a a2ensite B command to make the VM take effect.
Restart apache
Java code
/Etc/init. d/apache2 restart
Or reload apache2.
Java code
/Etc/init. d/apache2 reload
Modify the hosts file
Java code
Vi/etc/hosts
Insert the following two rows
127.0.0.1 www. linuxidc
127.0.0.1 www.linuxidc.net
When you access two domain names, you will find that they are resolved to different directories.
If you do not want to use a VM, you only need to execute the command.
Java code
A2dissite B
In this way, access to www.linuxidc.net cannot be correctly parsed.