Three ways to configure virtual host under Nginx

Source: Internet
Author: User

Nginx, a server tag is a virtual host.

1, the domain-based virtual host, through the domain name to differentiate the virtual host-application: external website

2, Port-based virtual host, through the port to differentiate the virtual host-application: The company's internal Web site, external Web site management background

3, IP-based virtual host, almost no.


Configure virtual host steps based on domain name:

Need to establish the/data/www/data/bbs directory, the Windows Local hosts add virtual machine IP address corresponding domain name resolution, the corresponding domain name site directory under the new index.html file;

The nginx.conf configuration file adds the following code:

server {Listen 80;   server_name www.yong.com;   Index index.html; Root/data/www;}   server {Listen 80;   server_name bbs.yong.com;   Index index.html; Root/data/bbs;}

Verify the results, use Curl test, or enter domain name access by the browser;

# curl-xlocalhost:80 Www.yong.comthis is Yong linux# curl-xlocalhost:80 bbs.yong.comthis are Yong BBS

Port-based virtual host configuration: use port to differentiate, browser use domain name or IP address: port number access;

server{Listen 8000;    server_name www.yong.com; Root/data/www;}    server{Listen 8001;    server_name www.yong.com; Root/data/bbs;}

Verify the results, use Curl test, or enter domain name access by the browser;

# Curl Www.yong.com:8000this is Yong linux# Curl Www.yong.com:8001this is Yong BBS

IP address-based virtual host configuration: access through IP, need to configure multiple IP;

# ifconfig Eth0:1 192.168.22.21
server{Listen 192.168.20.20:80;    server_name www.yong.com; Root/data/www;}    server{Listen 192.168.20.21:80;    server_name www.yong.com; Root/data/bbs;}


Verify the results, use Curl test, or enter domain name access by the browser;

# Curl 192.168.22.20this is Yong linux# Curl 192.168.22.21this is Yong BBS


This article is from the "Model Student's Learning blog" blog, please be sure to keep this source http://mofansheng.blog.51cto.com/8792265/1677849

Three ways to configure virtual host under Nginx

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.