Configuration of a domain name-based Apache Virtual Host in Ubuntu Linux

Source: Internet
Author: User

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.
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.