Nginx IP-based, port, domain configuration virtual host

Source: Internet
Author: User

Nginx (pronounced with engine x) is a lightweight Web server/reverse proxy server and e-mail (IMAP/POP3) proxy server that is released under a bsd-like protocol. It is characterized by the possession of less memory, concurrency is strong, in fact, nginx concurrency is actually in the same type of Web server performance better. Nginx as with Apache httpd, Nginx also provides IP-based, port-based and domain name mode to configure the virtual host.

First, what is a virtual host

Virtual host is the use of special hardware and software technology, a real physical server partition into multiple logical storage units. Each logical unit has no physical entity, but each logical unit can work on the network like a real physical host, with a separate IP address (or shared IP address), a separate domain name, and a complete Internet server (WWW, FTP, e-mail, etc.).

The key technology of the virtual host is that, even on the same hardware and the same operating system, there are different server programs open for multiple users, and they do not interfere with each other. And each user has its own part of the system resources (IP address, document storage space, memory, CPU, etc.). Each virtual host is completely independent, and it appears to the outside world that each virtual host and a single host are performing exactly the same. So this virtualized logical host is called a "virtual host".

Second, the Port-based virtual host

1. Prepare environment # Current Environment # more/etc/issuered Hat Enterprise Linux Server release 6.3 (Santiago) Kernel \ r on an \m# uname-rm2.6.32-279. el6.x86_64 x86_64# Nginx-vnginx version:nginx/1.8.0# create 3 directories for hosting different forms of virtual hosts index.html files # mkdir-p/website/baseport# mkdir -p/website/baseip# mkdir-p/website/basedomain# vi/website/baseport/index.html<html><head><title>Base Port Sample 
     title
 > 
     Head
 ><body><H1>This is an based port website sample (prot:8080). 
     H1
 > 
     Body
 > 
     HTML
 >2. Configure nginx.conf# First virtual host server {Listen 80;        server_name localhost;            Location/{root HTML;        Index index.html index.htm;        } #第二个虚拟主机 server {listen 8080;        server_name localhost;            Location/{root/website/port;        Index index.html index.htm; }}3, verify # nginx-t #语法检查 # service Nginx Reload #服务重载 # curl http://192.168.1.120:8080 #验证基于端口访问<html><head><title>Base Port Sample 
     title
 > 
     Head
 ><body><H1>This is an based port website sample (prot:8080). 
     H1
 > 
     Body
 > 
     HTML
 >

Third, IP-based virtual host

1, first add ip# ifconfig|grep "inet addr" inet addr:192.168.1.120 bcast:192.168.1.255 mask:255.255.255.0 inet addr:127.0.0.1 mask:255.0.0.0# ifconfig eth0:0 192.168.1.220 netmask 255.255.255.0 up #添加IP到eth0:0# ifconfig|grep "inet addr" inet addr:192.168.1.120 bcast:19 2.168.1.255 mask:255.255.255.0 inet addr:192.168.1.220 bcast:192.168.1.255 mask:255.255.255.0 inet AD        dr:127.0.0.1 mask:255.0.0.02, configuration nginx.conf# First virtual host server {Listen 80;        server_name localhost;            Location/{root HTML;        Index index.html index.htm; #第二个虚拟主机 server {listen 192.168.1.220:80;        server_name localhost;            Location/{Root/website/baseip;        Index index.html index.htm;         }}3, verify # nginx-t #语法检查 Author:leshami # service Nginx Reload #服务重载 blog:http://blog.csdn.net/leshami# Curl HTtp://192.168.1.220 #验证基于IP访问 <html><head><title>Base IP Sample 
     title
 > 
     Head
 ><body><H1>This is an based IP website sample. 
     H1
 > 
     Body
 > 
     HTML
 >

Four, domain-based virtual host

1. Modify/etc/hosts File # echo "192.168.1.120 bbs.ycdata.net bbs192.168.1.120 mail.ycdata.net mail>" >>/etc/hosts2,        Configure nginx.conf# First virtual host server {Listen 80;        server_name mail.ycdata.net;            Location/{root HTML;        Index index.html index.htm;        } #第二个虚拟主机 server {listen 80;        server_name bbs.ycdata.net;            Location/{root/website/baseport;        Index index.html index.htm; }}3, verify # Curl Http://mail.ycdata.net<html><head><title>Welcome to nginx! 
     title
 ><style> body{  width: +em;         margin:0 auto;     font-family: Tahoma, Verdana, Arial, Sans-serif; } 
     Style
 > 
     Head
 ><body><H1>Welcome to nginx! 
     H1
 ><p>If you see this page, the Nginx Web server is successfully installed andworking. Further configuration is required. 
     P
 ><p>For online documentation and refer<ahref="http://nginx.org/">nginx.org 
     a
 >.<br/>Commercial support was available at<ahref="http://nginx.com/">Nginx.com 
     a
 >. 
     P
 ><p><em>Thank for using Nginx. 
     em
 > 
     P
 > 
     Body
 > 
     HTML
 ># Curl Http://bbs.ycdata.net<html><head><title>Base Port Sample 
     title
 > 
     Head
 ><body><H1>This is an based port website sample (prot:8080). 
     H1
 > 
     Body
 > 
     HTML
 >

'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
  • '). Text (i)); }; $numbering. FadeIn (1700); }); });

    The above describes the Nginx based on IP, port, domain name configuration virtual host, including Nginx, virtual host aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.