Using the virtual host technology, you can divide a real host into many "virtual" hosts. Each virtual host has an independent domain name and IP address, and has a complete Internet server (www, FTP, email. Virtual Hosts are completely independent. in the outside world, each virtual host is exactly the same as an independent host. The effect is the same, but the cost is quite different. Because multiple virtual hosts share the resources of a real host, the hardware cost, network maintenance cost, and communication line cost of each virtual host user are greatly reduced, the Internet is truly an affordable network for everyone!
In the current production environment, most service providers use virtual hosts to provide web services to customers. virtual hosts include IP-based virtual hosts, port-based virtual hosts and name-based virtual hosts, because currently the most popular is name-based virtual hosts, that is, you can use the same port and IP address to correspond to multiple domain name sites, this experiment is based on this method.
1. Create site directories, home pages, and permissions
[Root @ rhel6u3-7 ~] # Uname-r // view system kernel version 2.6.32-279. el6.i686 [root @ rhel6u3-7 ~] # Cat/etc/redhat-release // view system version Red Hat Enterprise Linux Server release 6.3 (Santiago) [root @ rhel6u3-7 ~] #
[Root @ rhel6u3-7 nginx] # pwd
/Usr/local/nginx
[Root @ rhel6u3-7 nginx] # mkdir server sites // create server field configuration file directory as server, site home directory as sites
[Root @ rhel6u3-7 nginx] # mkdir sites/www sites/www1 // create a sub-site directory in the site home directory
[Root @ rhel6u3-7 nginx] # echo "This is www.rsyslog.org"> sites/www/index.html // create test Homepage
[Root @ rhel6u3-7 nginx] # echo "This is www1.rsyslog.org"> sites/www1/index.html // create test Homepage
[Root @ rhel6u3-7 nginx] # chown nginx. server/sites/-R // set the current owner and group to nginx
Ii. EditingNginxMaster configuration file, and addServerFields andLocationField. SetWww.rsyslog.orgAndWww1.rsyslog.orgTwo Virtual Hosts
[Root @ rhel6u3-7 nginx] # vim conf/nginx. conf
......... // Add the server field to the http module, and then add the location field to the server field.
Server {
Listen 80; // set the listener port of the VM to 80.
Server_name www.rsyslog.org; // sets the virtual host domain name
Location /{
Root sites/www; // set the relative path of the VM's home directory
Index index.html index.htm; // sets the default homepage of a VM.
}
Location/status {// view the current nginx status, which requires the module "-- with-http_stub_status_module" Support
Stub_status on;
Access_log/usr/local/nginx/logs/www_status.log; // set the log storage location and name it
Auth_basic "NginxStatus ";}
}
Include/usr/local/nginx/server/www1.rsyslog.org; // set the include statement to point to the location of the www1 Site server Field Configuration File
........
3. edit a websiteWww1.rsyslog.orgOfServerConfiguration File
[Root @ rhel6u3-7 ~] # Cd/usr/local/nginx/server/
[Root @ rhel6u3-7 server] # vim www1.rsyslog.org
Server {
Listen 80;
Server_name www1.rsyslog.org;
Location /{
Root sites/www1;
Index index.html index.htm;
}
Location/status {// view the current nginx status, which requires the module "-- with-http_stub_status_module" Support
Stub_status on;
Access_log/usr/local/nginx/logs/www1_status.log;
Auth_basic "NginxStatus ";}
}
4.DNSAdd twoARecord pointing to website host name
For DNS setup and configuration, see http://dreamfire.blog.51cto.com/418026/1091943
// Add the records of two websites to the DNS region File
Www A 192.168.100.107
Www1 A 192.168.100.107
5. StartNginxService, in order to facilitate the test to disable the firewall andSelinuxSetPremissiveMode
[root@rhel6u3-7 server]# /etc/rc.d/init.d/nginx restart
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Stopping nginx: [ OK ]
Starting nginx: [ OK ]
[root@rhel6u3-2 ~]# /etc/rc.d/init.d/iptables stop
[root@rhel6u3-2 ~]# setenforce 0
6. PassWindowsTo test the system, first set the network cardDNSSet192.168.100.102And thenNslookupWhether the command is successfully parsed.
PassIEBrowser access
AddStatusYou can view the current running status of the website
This article is from the blog of "the Linux open source technology blog", please be sure to keep this source http://dreamfire.blog.51cto.com/418026/1141018