Under Debian, Apache's virtual host configuration is based on multiple IP and virtual hosts based on multiple domain names.

Source: Internet
Author: User

Similar to the Apache virtual Host configuration under Windows platform, the only difference here is that the apache2 (installed through Apt-get) in Debian is in/etc/apache2

This article a space to teach you to implement multiple IP based on 127.0.0.* (Common network IP) to control the local virtual host, B space to teach you to implement a virtual host based on multiple domain names

The advantage of a is not to remember the name, but a little trouble. Direct access via IP. b The advantage is simple and quick, through the domain name direct access, do not have to stop the default configuration file.

A

Implemented in/www/my_project1 via local 127.0 0.2来 access

1: Create the Site configuration file

#touch/etc/apache2/sites-available/my_project1

#vim/etc/apache2/sites-available/my_project1

2: Enter after entering

<virtualhost 127.0.0.2:80>

ServerName 127.0.0.2

Documentroot/home/www/my_project1

</VirtualHost>

3: Activate the site, stop the default

#a2dissite Default

#a2dissite Default-ssl

#a2ensite My_project1

(Note that the default of the other configuration, you need to migrate to here)

Create a httpd.conf file inside/home/www/my_project1

<virtualhost 127.0.0.2:80>
ServerName My_project1
Documentroot/home/www/my_project1

<Directory/home/www/my_project1>
AllowOverride All
Options All
</Directory>
</VirtualHost>

And then in the top 2 inside the file loads this httpd.conf

Include/home/wwwmy_project1/httpd.conf


4: Load the site

/etc/init.d/apache2 Reload

5: Modify the hosts to point to 127.0.0.2

#vim/etc/hosts

Join

127.0.0.2 My_project2

Open the browser input 127.0.0.2 can access to/home/www/my _project1

Other items that need to be added can be modified to add the corresponding content in turn.


B

Implement to access/home/www/my_project2 in the browser input my_project2.com

1: Create the Site configuration file

#touch/etc/apache2/sites-available/my_project2

#vim/etc/apache2/sites-available/my_project2

2: Enter after entering

<virtualhost *:80>

ServerName my_project2.com

Documentroot/home/www/my_project2

</VirtualHost>

3: Activate the site

#a2ensite My_project2

4: Load the site

/etc/init.d/apache2 Reload

5: Modify the Hosts

#vim/etc/hosts

Join

127.0.0.1 my_project2.com

Open the browser input my_project2.com can access to/home/www/my _project2

Other items that need to be added can be modified to add the corresponding content in turn.

Add it directly to the MY_PROJECT2.

<virtualhost *:80>

ServerName my_project3.com

Documentroot/home/www/my_project3

</VirtualHost>

And then

#a2ensite My_project2

Add the corresponding domain name in the host My_project3 point to 127.0.0.1

#/etc/init.d/apache2 reload can access the corresponding by my_project1.com and my_project2.com.

b This method is recommended for use.



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.