PHP beginners: configure the Apache server and set DNS

Source: Internet
Author: User
Of course, the main technical content is the DNS resolution, I am responsible for our company, first look up the information said... '& nbsp; generally, the virtual host technology refers to the resources (system resources, network bandwidth, and storage space) of one (or a group) server) a certain proportion is divided into several SyntaxHighlighter instances. all (); of course, the main technical content is the point of DNS resolution, I am responsible for our company, first look up the information said...'

Generally, the virtual host technology refers to the resources (system resources, network bandwidth, and storage space) of one (or a group) server) the technology is divided into several relatively independent "small hosts" according to a certain proportion. Each such "small host" can implement basic Internet services such as WWW, FTP, and Mail, just like using an independent host.
 
Currently, the web server's virtual host platform uses Apache as the most open platform, followed by Microsoft's Windows IIS. Apache has the advantages of cross-platform (FreeBSD/Linux/Windows/Solaris/Other UNIX), ease of maintenance and optimal security.
Apache is one of the first servers that support IP-based virtual hosts. Apache 1.1 and later versions support both IP-based and host-name-based virtual hosts. different virtual hosts are sometimes called host-based) or non-IP virtual hosts ).

You can use Apache to set up the VM service in two ways: IP address-based virtual host and host name-based virtual host. The following describes their implementation methods and advantages and disadvantages. So that you can select the most appropriate implementation method in specific applications.

I. Apache implements IP address-based virtual hosts (each site has an independent IP address)

To use this virtual host method, you must first set an IP address for each virtual host on the server. These IP addresses can be completed by adding multiple NICs or setting up multiple IP addresses on one Nic. With multiple IP addresses, you can set Apache in either of the following two ways.

1. run an Apache copy for each VM
In this way, each Apache program can be run by a single user, so each virtual host does not affect each other. When setting such a VM, you only need to set a configuration file for each Apache Copy. The only thing you need to note is that you must use the "Listen" statement, each copy of Apache is forced to receive service requests only on its own IP address.

Advantage: each virtual host does not interfere with each other, and the security is high.
Disadvantage: it occupies a large amount of system resources.

2. multiple virtual hosts share the same Apache
In this way, each virtual host shares the same Apache, so there is a certain impact between each virtual host, especially when executing CGI programs, it may bring some serious security problems. When setting such a VM, you only need to set the following information for each VM:

DocumentRoot/www/ghq1
...

Advantage: less system resources are occupied than the previous method.
Disadvantage: low security. Each virtual host still needs one IP address.


For example, the server is bound with two IP addresses (172.16.3.40 and 172.16.3.50) to the services of www.ghq1.com and www.ghq2.org respectively. the configuration is as follows:

Server Configuration (httpd. conf)
Listen 80


DocumentRoot/www/ghq1
ServerName www.ghq1.com


DocumentRoot/www/ghq2
ServerName www.ghq2.org

Simple configuration description: the "Listen" default httpd service monitors the communication port No. 80th. the "Listen" option allows you to specify the IP address or communication port monitored by the apache server.

"DocumentRoot": specifies the root directory for storing web pages on the apache server. "ServerName": Allows users to set their own host names. this name will be sent to the remote connection program, to replace the real name of the apache server host. And The syntax structure of the VM. the IP address is the different IP addresses bound to the server, or the IP address and the communication port number (see the following example ).

If the server has two IP addresses (172.16.3.40 and 172.16.3.50) corresponding to the domain name www.ghq1.com and www.ghq2.org respectively. For each domain name, we want to publish our website on port 80 and port 8080. You can configure it as follows:

Server Configuration (httpd. conf)
Listen 172.16.3.40: 80
Listen 172.16.3.40: 8080
Listen 172.16.3.50: 80
Listen 172.16.3.50: 8080


DocumentRoot/www/ghq1-80
ServerName www.ghq1.com


DocumentRoot/www/ghq1-8080
ServerName www.ghq1.com


DocumentRoot/www/ghq2-80
ServerName www.ghq1.org


DocumentRoot/www/ghq2-8080
ServerName www.ghq2.org

Therefore, to create a VM, we must resolve the domain names corresponding to different IP addresses and create directories (such as/www/ghq1 ), store the corresponding homepage content in the corresponding directory.

II. Apache implements host name-based VM service (one IP address implements multiple websites)

The virtual host service based on the host name is a common solution for virtual hosts. Because it does not require more IP addresses, there is no need for special hardware and software support. Most browsers now support the implementation of such virtual hosts. The domain name-based VM is determined based on the host name section in the HTTP header submitted by the client. With this technology, many virtual hosts can enjoy the same IP address.

Domain name-based virtual hosts are relatively simple, because we only need to configure the DNS server to map each host name (CNAMES) to the correct IP address, and then configure the Apache HTTP Server, so that you can identify different host names. Domain name-based servers can also alleviate the problem of insufficient IP addresses (IPV4 addresses. In this way, each virtual host shares the same Apache. Therefore, when a CGI program is running, the security is not high.

Advantage: a single IP address can provide a large number of VM services.
Disadvantage: poor security. To maintain these virtual hosts, you must change the configuration file and restart the Apache process. Therefore, it is not suitable for large-scale VM services.

If the server only has one IP address, there are many mappings in the DNS to this machine. We want to run www.ghq1.com and www.ghq2.org on this machine. Creating a virtual host in the Apache server configuration does not automatically update the host name in DNS. We must add a domain name in the DNS to point to our IP address. Otherwise, the website cannot be viewed by others.

Server Configuration (httpd. conf)
# Ensure that Apache listens on port 80
Listen 80

# Listen for virtual host requests on all IP addresses
NameVirtualHost *


DocumentRoot/www/ghq1
ServerName www.ghq1.com

# Other directives here


DocumentRoot/www/ghq2
ServerName www.ghq2.org

# Other directives here

Because * (asterisk) matches all addresses, the master server does not receive any requests. Because www.ghq1.com first appears in the configuration file, it has the highest priority and can be considered as the default or primary server. This means that if an accepted request cannot match a ServerName command, it will be servo by the first VirtualHost.

When our IP addresses cannot be determined, it is very convenient to use *. for example, the ISP configures Dynamic IP addresses (such as ADSL dial-up Internet access) for us ), however, when we use a dynamic domain name resolution system. Because * matches any IP address, in this case, no additional configuration is required regardless of how the IP address changes. In most cases, we use domain name-based virtual hosts.

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.