Configuration of Apache Virtual Hosts in Linux

Source: Internet
Author: User

Configuration of Apache Virtual Hosts in Linux

The httpd version selected in this article is also the httpd-2.2.4.

Access to web Services is essentially a port (80 by default) on the host that accesses an IP address ). Generally, you need to access different websites by accessing different domain names or ports (specifically to different directories on the server). In this case, you need to set the virtual host (VirtualHost ). there are usually three types: (1) host-based (2) Port-based (3) IP-based and the combination of these three methods. The ip address of the VM is 192.168.109.40. The ip address of the local machine is 192.168.20..1. Preparations: Disable the firewall and go to the apache configuration file httpd. conf find this line and comment out DocumentRoot "/usr/local/apache/htdocs" and find # Virtual hosts # Include/etc/httpd/extra/httpd-vhosts.conf to enable the second line, then enter the/etc/httpd/extra/httpd-vhosts.conf so that the preparation is complete, the following are three ways to set the virtual host. 1. IP-based VM configuration method. We can bind multiple IP addresses to eth0. You can use the ip addr add ip address dev eth0 to bind an ip address. Here we bind the IP addresses 192.168.109.41 and 192.168.109.42. Use ip addr show to view the bound information, as shown in, And then modify the content in the/etc/httpd/extra/httpd-vhosts.conf. For example: serverName www.a.com set the virtual host name to www.a.com DocumentRoot "/www/B .com" web page storage location Options none AllowOverride none Require all granted ErrorLog "/var/log/httpd/B .com-error_log" CustomLog" the same applies to/var/log/httpd/B .com-access_log "common, for a VM with 192.168.109.42 configured, you only need to copy the VM according to the above content, and then modify the corresponding location. Because we put the web page under/www/a.com and/www/B .com, create these two directories mkdir-p/www/a. commkdir-p/www/B .comand create the test file index.html in a.comand B .com. The content of index.html in a.comis as follows: the content of index.html in a.comb.comis: restart apache after B .com is configured and access 192.168.109.41, as shown in figure
Access 192.168.109.42, as shown in figure
We are accessing the Virtual Machine ip address 192.168.109.40.
From this we can know that the configuration is successful. 2. The port-based virtual host configuration method. You must first modify the configuration file/etc/httpd. conf ,:
The default listening port is 80. To configure a virtual host based on port 8080, add the following line: Listen 8080 to save and exit. Then modify the file/etc/httpd/extra/httpd-vhosts.conf. Take the IP address 192.168.109.41 as an example: we have to create the/www/c.com directory. For more information, see the previous section. Access 192.168.109.41: Port 80, as shown in
Access 192.168.109.41: 8080, as shown in
From this we can know that the configuration has been successful. 2. The domain name-based virtual host configuration method because we do not have a DNS server in the local configuration, we need to resolve it locally, now, the ip address 192.168.109.42 is used as an example for local DNS resolution: open my computer and modify the hosts file 192.168.109.42 www in C: \ Windows \ System32 \ drivers \ etc. b. com192.168.109.42 www.d.com add the two rows. Then in the same way as modifying the file/etc/httpd/extra/httpd-vhosts.conf, you have to create/www/d.com which is not described here. Access www. B .com, as shown in
Access www.d.com, as shown in

Install a Web Server on Ubuntu Server 14.04 (Linux + Apache + MySQL + PHP)

Install and configure the PHP environment in Linux (Apache2)

Install the LAMP \ Vsftpd \ Webmin \ phpMyAdmin service and settings in Ubuntu 13.04

Compile and install LAMP in CentOS 5.9 (Apache 2.2.44 + MySQL 5.6.10 + PHP 5.4.12)

Source code for Web server architecture in RedHat 5.4 build the LAMP environment and application PHPWind

Apache details: click here
Apache: click here

This article permanently updates the link address:

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.