Configure the virtual host (APACHE virtualhost) in apache22)

Source: Internet
Author: User

The role of Apache virtualhost is to enable one Apache to serve multiple domain names. It is equivalent to a server that has more than N websites. For example:

My Apache server, IP address X. x. x. x. I have two domain names www.tootoogo.org and lp.tootoogo.org. Set these two domain names to direct to X. x. x. x. After the virtual host is set on the Apache server, the Apache server can simultaneously serve the two domain names so that the two domain names direct to different webpages respectively, so one of my servers has two websites at the same time.

Apache virtualhost configuration method:
Add the following content at the end of the httpd. conf file:

Namevirtualhost *: 80

<Virtualhost *: 80>
Serveralias www.tootoogo.org # It seems that this line is unnecessary
Directoryindex index.html index. php
DocumentRoot "/var/www/data1/"
Servername www.tootoogo.org
Errorlog "log/tootoogo-error_log"

Customlog "logs/tootoogo. Access"

</Virtualhost>

<Virtualhost *: 80>
Directoryindex index.html index. php
DocumentRoot/var/www/data2/

Servername lp.tootoogo.org

Errorlog "log/LP. tootoogo-error_log"

Customlog "logs/LP. tootoogo. Access"

</Virtualhost>

In this way, you can use two domain names to resolve to the same IP address but get different pages.

If you want to disable direct access using IP addresses
Namevirtualhost *: 80
Insert the following content after this sentence:

<Virtualhost *: 80>
Servername youripaddress
<Location/>
Order allow, deny
Deny from all
</Location>
</Virtualhost>

Note:

Modify
<Directory "/usr/local/www/apache22/Data">
Is
<Directory "/usr/local/www/apache22/">
Then you can
Use the following directory to place the webpages corresponding to these two domain names.
DocumentRoot/usr/local/www/apache22/data1
DocumentRoot/usr/local/www/apache22/data1

///// // Out-of-the-box ////////////

To listen to other port numbers, you can add

Listen yourip: port, for example, listen 192.168.1.1: 8081, then the corresponding

Namevirtualhost *: 8081 <virtualhost *: 8081>

Servername www.tootoogo.org: 8081

//////////////////////////////////

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.