Tip: ApacheServer sets virtual WEB

Source: Internet
Author: User
Tags tld dedicated ip domain name registration in domain subdomain
Article title: Tip: ApacheServer sets virtual WEB. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
The settings for using apache server on unix and NT platforms are the same. The following describes how to configure apache server on the unix platform. In addition, it is worth noting that about 50% of the workload for successful virtual web settings is in domain name registration and resolution. Therefore, you should register the domain name before setting the virtual WEB.
  
   I. IP-type VM
An IP host is the unique IP address of each VM. Multiple IP addresses can be implemented through multiple physical NICs or virtual network interfaces. both Solaris2.5 and Windows NT support this method.
You can configure multiple VM instances in either of the following ways:
1. start an httpd process for each VM.
Use this method in the following cases:
1) security isolation needs to be considered. for example, two httpd instances run on different users, groups, Listen, and ServerRoot instances. in addition to browsing data through the Web, the two users cannot access other data.
2) provides sufficient memory and file descriptors.
Setting method:
Create an independent httpd installation for each virtual host. in the configuration file httpd. conf of each installation path, use the Listen command to specify the IP address of the process service, for example, Listen 10.68.37.10: 80.
2. start an httpd process for all virtual hosts.
Use this method in the following cases:
1) allows sharing httpd configurations between virtual hosts.
2) computers serve a large number of requests and run multiple processes to reduce server performance.
Setting method:
In the configuration file httpd. conf, use the VirtualHost command to set ServerAdmin, ServerName, DocumentRoot, ErrorLog, TransferLog, or CustomLog for each virtual host, for example:
   ServerAdmin webmaster@mail.smallco.com
DocumentRoot/usr/local/etc/httpd/htdocs/smallco
ServerName www.smallco.com # We recommend that you use a domain name here
ErrorLog/usr/local/etc/httpd/logs/smallco/error_log
TransferLog/usr/local/etc/httpd/logs/smallco/access_log
     ServerAdmin webmaster@mail.baygroup.org
DocumentRoot/groups/baygroup/www
ServerName www.baygroup.org # domain names are recommended here
ErrorLog/groups/baygroup/logs/error_log
TransferLog/groups/baygroup/logs/access_log
  At the same time, you need to configure the virtual network port or network card, and configure the corresponding settings in DNS.
  
   II. name-based VM (supported by Apache1.3 and later versions)
Although the IP type VM is good, it is not the best solution. It requires each VM to have a dedicated IP address, which is difficult to implement on some machines. A name-based VM has different names, but the IP address is the same. It does not limit the number of virtual hosts. it is easy to configure and use and does not require additional hardware and software. The disadvantage is that the client must support this part of the protocol, which is supported by browsers of recent versions. some earlier versions of browsers do not. However, Apache provides a solution for this.
Setting method:
In the configuration file httpd. conf, use the NameVirtualHost command to set the virtual host, for example:
NameVirtualHost 111.22.33.44
   ServerName www. domain. tld # domain name is recommended here
DocumentRoot/web/domain
  At the same time, the DNS defines www. domain. tld pointing to 111.22.33.44.
Note: When the IP address is used after the NameVirtualHost command, any URL request using the IP address is for the VM, and the master server will never respond to a URL request using the IP address. In addition, some servers want to be accessed by multiple names. For example, if a server with an IP address wants to be accessed by domain. tld and www2.domain. tld, the ServerAlias command is used in the VirtualHost command. For example, ServerAlias domain. tld *. domain. tld
Additional VM configuration instances are provided.
  
Appendix: VM instance settings
IP-type VM configuration
Setup 1: The server has two IP addresses,
111.22.33.44 server. domain. tld
111.22.33.55 www. otherdomain. tld
Www. domain. tld is the alias of server. domain. tld (CNAME), representing the master server.
Server configuration:
...
Port 80
DocumentRoot/www/domain
ServerName www. domain. tld
   DocumentRoot/www/otherdomain
ServerName www. otherdomain. tld
...
  Setup 2: basically the same as Setup1, but no dedicated master server is set.
Server configuration:
...
Port 80
ServerName server. domain. tld
   DocumentRoot/www/domain
ServerName www. domain. tld
...
     DocumentRoot/www/otherdomain
ServerName www. otherdomain. tld
...
  This setting hits the master server only when the URL is http://server.domain.tld
Setup 3: The server has two IP addresses,
111.22.33.44 server. domain. tld
111.22.33.55 www-cache.domain.tld
Www. domain. tld is the alias of server. domain. tld (CNAME), representing the master server.
The www-cache.domain.tld is the proxy-cache, the port is 8080, and the Web server uses the default 80.
Server configuration:
...
Port 80
Listen 111.22.33.44: 80
Listen 111.22.33.55: 8080
ServerName server. domain. tld
   DocumentRoot/www/domain
ServerName www. domain. tld
...
     ServerName www-cache.domain.tld
...
   Order deny, allow
Deny from all
Allow from 111.22.33
      
Name-based VM configuration
Setup 1: The server has an IP address,
111.22.33.44 server. domain. tld.
Www. domain. tld and www. sub. domain. tld are aliases (CNAMEs ).
Server configuration:
...
Port 80
ServerName server. domain. tld
NameVirtualHost 111.22.33.44
   DocumentRoot/www/domain
ServerName www. domain. tld
...
     DocumentRoot/www/subdomain
ServerName www. sub. domain. tld
...
  If you use an IP address to access the server, because www. domain. tld has the highest priority, it is considered as the default server or
Server 1.
Setup 2: The server has two IP addresses,
111.22.33.44 server1.domain. tld for master server
111.22.33.55 server2.domain. tld for VM
The alias www. domain. tld is used for the master server,
The alias www. otherdomain. tld is used for a VM,
The alias www. sub. domain. tld, *. sub. domain. tld is used for another VM,
Server configuration:
...
Port 80
ServerName www. domain. tld
DocumentRoot/www/domain
NameVirtualHost 111.22.33.55
   DocumentRoot/www/otherdomain
ServerName www. otherdomain. tld
...
     DocumentRoot/www/subdomain
ServerName www. sub. domain. tld
ServerAlias *. sub. domain. tld
...
  Hybrid (IP/name) VM configuration
Setup: The server has three IP addresses,
111.22.33.44 server. domain. tld is used for name-type virtual hosts
111.22.33.55 www. otherdomain1.tld for IP-type virtual hosts
111.22.33.66 www. otherdomain2.tld for IP-type virtual hosts
Server configuration:
...
Port 80
ServerName server. domain. tld
NameVirtualHost 111.22.33.44
   DocumentRoot/www/domain
ServerName www. domain. tld
...
     DocumentRoot/www/subdomain1
ServerName www. sub1.domain. tld
...
     DocumentRoot/www/subdomain2
ServerName www. sub2.domain. tld
...
     DocumentRoot/www/otherdomain1
ServerName www. otherdomain1.tld
...
     DocumentRoot/www/otherdomain2
ServerName www. otherdomain2.tld
...
  Port-type VM configuration
Setup: The server has an IP address,
111.22.33.44 www. domain. tld
If you do not need another alias or IP address, you can use a port-type virtual host to set a virtual server with different configurations.
VM instance.
Server configuration:
...
Listen 80
Listen 8080.
ServerName www. domain. tld
DocumentRoot/www/domain
   DocumentRoot/www/domain2
  
Related Article

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.