PHP Beginner: Configure Apache server and set DNS

Source: Internet
Author: User
Tags port number root directory

Of course, the main technical content is the point of DNS resolution, I am responsible for our company, first check the information said ... '

We usually say that the virtual host technology is a (or a group) of the server resources (system resources, network bandwidth, storage space, etc.) according to a certain proportion of the partition into a number of relatively independent "small host" technology. Each such "small host" in the function can realize www, FTP, mail and other basic Internet services, like using a stand-alone host.

Currently, the Web server's virtual host platform uses the most open Apache, followed by Microsoft's Windows IIS. Apache has the advantages of Cross-platform (Freebsd/linux/windows/solaris/other UNIX), ease of maintenance, and best security.

Apache is one of the first servers to support ip-based virtual hosts. Apache 1.1 and its newer version also support ip-based and host-based virtual hosts, and different virtual hosts are sometimes referred to as host-based (host-based) or non-IP virtual hosts (NON-IP).

There are usually two scenarios for setting up a virtual host service with Apache: Virtual hosts based on IP addresses and host-name virtual hosts, and here are some of the ways to implement them and their pros and cons. So that we can choose the most suitable implementation method in the concrete application.

First, Apache implementation of IP address based virtual host (each site has a separate IP address)

With this type of virtual host, you first set up a separate IP address for each virtual host on the server. These IP addresses can be completed by adding multiple network adapters or by setting up multiple IP addresses on a single network card. With multiple IP addresses, you can set up Apache in one of the following two ways.

1, for each virtual host to run an Apache

In this way, each Apache program can be run by a separate user, so each virtual host does not affect each other. When setting up this virtual host, just set up a set of configuration files for each Apache, the only thing to be aware of is that you must use the "Listen" statement to force each Apache to receive a service request only on its own IP address.

Advantages: Each virtual host between the mutual interference, high security.

Disadvantage: Occupy system resources more.

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 the execution of CGI programs, may bring some serious security problems. When you set up this virtual host, you can set up information similar to the following for each virtual host:

  <VirtualHost www.ghq1.com>
  DocumentRoot /www/ghq1
  …
  </VirrualHost>

Advantage: Less system resources than the previous one.

Disadvantage: Low security, each virtual host still needs to occupy an IP address.

For example, the server is bound to a network card with two IP addresses (172.16.3.40 and 172.16.3.50) corresponding to the domain name www.ghq1.com and www.ghq2.org services, configured as follows:

Server configuration (Apache configuration file httpd.conf)

  Listen 80
  
  <VirtualHost 172.16.3.40>
  DocumentRoot /www/ghq1
  ServerName www.ghq1.com
  </VirtualHost>
  
  <VirtualHost 172.16.3.50>
  DocumentRoot /www/ghq2
  ServerName www.ghq2.org
  </VirtualHost>

Configuration brief description: The "Listen" default httpd service monitors the 80th communication port, and the "Listen" option allows the user to specify the IP address or communication port that the Apache server monitors.

"DocumentRoot": Specifies the root directory where the Apache server holds the Web page; "ServerName": Allows users to set their own hostname, which is sent to the remote connector to replace the actual name of the Apache server host installation. <virtualhost IP > and </VirtualHost> constitute the syntactic structure of the virtual host, where the IP is the different IP address that we bind on the server, or the IP address plus the communication port number (see example below).

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, we would like to post our website on 80 ports and 8080 ports. You can configure this:

Server configuration (Apache configuration file 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
  
  <VirtualHost 172.16.3.40:80>
  DocumentRoot /www/ghq1-80
  ServerName www.ghq1.com
  </VirtualHost>
  
  <VirtualHost 172.16.3.40:8080>
  DocumentRoot /www/ghq1-8080
  ServerName www.ghq1.com
  </VirtualHost>
  
  <VirtualHost 172.16.3.50:80>
  DocumentRoot /www/ghq2-80
  ServerName www.ghq1.org
  </VirtualHost>
  
  <VirtualHost 172.16.3.50:8080>
  DocumentRoot /www/ghq2-8080
  ServerName www.ghq2.org
  </VirtualHost>

Therefore, the establishment of virtual host, we have to do a different IP corresponding domain name resolution work, set up a corresponding directory (such as/WWW/GHQ1), the corresponding home page content in the corresponding directory can be.

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.