Two programs for achieving Apache virtual hosts

zhaozj2021-02-08  238

Two programs for achieving Apache virtual hosts

Author: Wu Ah Ting

Introduction: The virtual host that is hereby refers to only one httpd background program on one machine.

Support multiple Apache servers, such as a web server in the corporate finance department, named

Account.yourDomain.com, and also want to establish a website for the Sales department, website content

Put on the machine, access to Sales.YourDomain.com, this is to use the virtual host

Set.

Setting Apache virtual hosts usually have two programs

First, IP-based virtual host

This method needs to set IP alias on the machine, like an example above, in a machine

Bind multiple IP addresses on the NIC to serve multiple virtual hosts.

If the IP address of the machine is 192.168.11.2 (Account.YourDomain.com, first

You have to set the IP alias (assuming 192.168.11.4 as its alias IP). Add a line

/etc/rc.d/rc.local ensures that automatically runs automatically after each startup.

# / sbin / ifconfig eth0: 0 192.168.11.4 Netmask 255.255.255.0 Broadcast 192.168.11.255 Up

# / sbin / route add -host 192.168.11.4 eth0: 0

Then you need to set the /etd/httpd/conf/httpd.conf file:

"VirtualHost 192.168.11.4" *

ServerAdmin webmaster@yourdomain.com

DocumentRoot /Home/httpd/sales.YourDomain.com

ServerName Sales.YourDomain.com

ErrorLog / Var/log/httpd/sales.yourDomain.com/error_log

Transferlog /var/log/httpd/sales.yourdomain.com/access_log

"/ Virtualhost"

Then create a directory separately

/Home/httpd/sales.yourdomain.com,

/var/log/httpd/sales.YourDomain.com

, Put the corresponding website content to the directory /Home/httpd/sales.YourDomain.com You can, and make sure

Your internal DNS specifies the a record of Sales.YourDomain.com to the IP address 192.168.11.4.

Note: This IP-based virtual host has a shortcoming, that is, you need more IP addresses to serve their respective

Virtual host, if you have only one IP address, then you will be able to consider name-based virtual hosts

Program.

Second, the name-based virtual host:

Its advantage is that there is no need for more IP addresses, easy to configure, no other hardware and software, modern

Most of the browser supports this approach. Like IP-based virtual hosts, you need to edit files

/etc/httpd/conf/httpd.conf

NamevirtualHost 192.168.11.2

"VirtualHost 192.168.11.2"

ServerAdmin webmaster@yourdomain.com

DocumentRoot /Home/httpd/sales.YourDomain.com

ServerName Sales.YourDomain.com

ErrorLog / Var/log/httpd/sales.yourDomain.com/error_log

Transferlog /var/log/httpd/sales.yourdomain.com/access_log

"/ Virtualhost"

"VirtualHost 192.168.11.2"

ServerAdmin Webmaster@yourDomain.comDocumentRoot /Home_httpd/hr.YourDomain.com

ServerName Hr.YourDomain.com

ErrorLog / Var/log/httpd/hr.YourDomain.com/error_log

Transferlog /var/log/hr.yourdomain.com/access_log

"/ Virtualhost"

Note: You need to add NameVirtualHost instructions to the forefront, below the virtual host,

In order to make it work, you need to put the DNS of Sales.yourDomain.com, Hr.YourDomain.com

Both point to IP address 192.168.11.2

The two of the above will work, if it is in the external network segment, provide WWW service on the Internet, you may

Without enough real IP addresses to support multiple virtual hosts, you can use the name-based virtual host solution.

If you have more internal retention IP addresses on the internal network segment, there will be no difference.

Jephe wu

* "" "", Actually "<>"

转载请注明原文地址:https://www.9cbs.com/read-1824.html

New Post(0)