Nginx virtual host configuration (two)

  Web Hosting is the use of special hardware and software technology to a host computer into multiple "virtual" host, each virtual host has a separate domain name and IP address (or shared IP address), a complete Internet server Features. On the same hardware, same operating system on servers running different programs that are open for multiple users, without disturbing each other; and each user have their own part of the system resources (IP address, file storage space, memory, CPU time, etc. ).

  The use of virtual hosts, without providing a separate site for each Nginx server you want to run or run a set Nginx process alone. Web Hosting provides the ability to run on the same server, Nginx process the same set of multiple sites.

Under nginx, a server is a virtual host label. Configuring virtual host in three ways:

  • Based virtual hosting, a domain name to distinguish between virtual hosts - Application: External Website
  • Port-based virtual hosting, through the port to distinguish between virtual hosts - Application: the company's internal Web site, external website management background
  • Ip-based virtual hosting, the basic need

First, based on domain name

Under hosts need to modify the file, plus the corresponding relationship between IP and domain names, or else access is not visible.

vim /etc/hosts
192.168.22.33 www.test.com
192.168.22.33 www.cookie.com

nginx.conf file in the editor nginx

{Server # virtual host 
    the listen 80; # listening port 
    server_name www.test.com; # monitor domain 
    Localtion / { 
            the root HTML -ling; # root positioning 
            index index.html; 
    } 
} 
Server { 
    the listen 80 ; 
    server_name WWW. cookie.com; 
    LOCATION / { 
        the root HTML - Wang; 
        index index.html; 
    } 
}

Then access the appropriate domain name www.test.com or www.cookie.com will be a corresponding index interface.

Second, based on the port

 

Third, based on IP

To each server to configure an IP, Different direct access to IP will visit virtual host.

 

Guess you like

Origin www.cnblogs.com/myitnews/p/11532837.html