Two options for doing virtual hosts with apache

xiaoxiao2021-03-18  197

Introduction: The virtual host here is that only one httpd background program is running only one HTTPD background program to support multiple Apache servers. If there is a web server in the corporate finance department, named Account.YourDomain.com, and I want to be the Sales department. Establish a website, the content of the website is also placed on the machine, access to Sales.YourDomain.com, which is used to use the virtual host settings.

Setting Apache virtual hosts usually have two programs

First, IP-based virtual host

This way is required to set an IP alias on the machine, and the above example is bound to a plurality of IP addresses to serve multiple virtual hosts on a machine's NIC. 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). Plus the down to /etc/rc.d/rc.local to ensure that automatically runs 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: 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

Then create a directory /Home/httpd/sales.yourdomain.com, /var/log/httpd/sales.yourDomain.com, put the corresponding website content to the directory /Home/httpd/sales.yourDomain.com, go down, and Make sure that the DNS in your internal DNS specifies the A record to the IP address 192.168.11.4.

Note: This IP-based virtual host has a shortcomings, that is, you need more IP addresses to serve their respective virtual hosts, if you have only one IP address, you will be able to consider the name-based virtual host solution.

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 hardware, modern browsers support this approach. Like IP-based virtual host, you need to edit files /etc/httpd/conf/httpd.conf

NamevirtualHost 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

ServerAdmin webmaster@yourdomain.com DocumentRoot /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 Note: You need to add NameVirtualHost instructions to the forefront, in turn, in turn, in order to make it work, you need to point Sales.YourDomain.com, Hr.YourDomain.com's DNS all points to IP address 192.168.11.2

The above two will work, if it is in the external network segment, the WWW service is provided on the Internet, you may not have enough real IP addresses to support multiple virtual hosts, you can use the name-based virtual host scenario, if it is in the internal network On the paragraph, you have more internal retention IP addresses, which will not be too big.

Jephe wu

China Linux Forum Copyright

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

New Post(0)