Ways to add virtual host functionality to the Apache server _linux

Source: Internet
Author: User
Tags mkdir

Apache default hosting page root directory, is under/var/www/html/, that is, by default, a server, can only run a Web site. But a good performance of the server, if only run a website, is not a bit wasteful? In fact, Apache is to support the virtual host function, to the virtual host mode can run N sites.

The way Apache turns on the virtual host feature is also simple, taking CentOS 6.3 and Apache 2.2 as an example, creating a vhost.conf configuration file in the/etc/httpd/conf.d/directory with the following content format:

Namevirtualhost *:80

<virtualhost *:80>
   ServerName
   aaa.com serveralias www.aaa.com documentroot/srv/www/aaa.com/public_html/
</VirtualHost>

<virtualhost *:80>
   ServerName bbb.com
   serveralias www.bbb.com
   documentroot/srv/www/bbb.com/public_html/
</VirtualHost>

Then create the appropriate directories for the two sites:

$ mkdir-p/srv/www/aaa.com/public_html
$ mkdir-p/srv/www/bbb.com/public_html

In the above two domain names, add a record point to the IP address of the server, and then restart the Apache server:

$ Service httpd Restart

If you need to log access logs and error logs, as well as implement URL rewriting functions, you will also need to make the following modifications:

<virtualhost *:80>
   ServerAdmin webmaster@aaa.com
   ServerName
   aaa.com serveralias www.aaa.com documentroot/srv/www/aaa.com/public_html/
   errorlog/srv/www/aaa.com/logs/error.log
   customlog/srv/www/ Aaa.com/logs/access.log combined
   <Directory/srv/www/aaa.com/public_html/>
     Options followsymlinks
     allowoverride
     All Order Allow,deny
     allow from all
   </Directory>
</VirtualHost>

At this point, the virtual host is created to complete, with different domain name access, the server will return different content.

Additionally, if you use an IP address to access the server at this point, the returned content will no longer be the content of the/var/www/html/, but the contents of the first virtual host in the vhost.conf configuration file.

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.