Three methods for configuring virtual hosts in Nginx

Source: Internet
Author: User

Three methods for configuring virtual hosts in Nginx

In Nginx, a server label is a virtual host.

1. Domain Name-based virtual hosts use domain names to differentiate virtual hosts-Applications: External Websites

2. Port-based virtual hosts differentiate virtual hosts through ports-Applications: internal websites of the company and Management backend of external websites

3. There is almost no need for ip-based virtual hosts.

To configure a VM based on a Domain Name:

You need to create a/data/www/data/bbsdirectory. The domain name corresponding to the IP address of the windows‑hosts‑host virtual machine must be added to the index.html file under the domain name website directory;

The following code is added to the nginx. conf configuration file:

Server {

Listen 80;

Server_name www.bkjia.com;

Index index.html;

Root/data/www;

}

Server {

Listen 80;

Server_name bbs.bkjia.com;

Index index.html;

Root/data/bbs;

}


Test the verification result using curl or enter the domain name in the browser for access;

# Curl-xlocalhost: 80 www.bkjia.com

This is bkjia linux

# Curl-xlocalhost: 80 bbs.bkjia.com

This is bkjia bbs

Port-based Virtual Host Configuration: port is used for distinguishing, And the browser uses the domain name or IP Address: port number for access;

Server

{

Listen 8000;

Server_name www.bkjia.com;

Root/data/www;

}

Server

{

Listen 8001;

Server_name www.bkjia.com;

Root/data/bbs;

}


Test the verification result using curl or enter the domain name in the browser for access;

# Curl www.bkjia.com: 8000

This is bkjia linux

# Curl www.bkjia.com: 8001

This is bkjia bbs


Ip address-based VM configuration: Multiple ip addresses are required for access through ip addresses;

# Ifconfig eth0: 1 192.168.22.21

Server

{

Listen 192.168.20.20: 80;

Server_name www.bkjia.com;

Root/data/www;

}

Server

{

Listen 192.168.20.21: 80;

Server_name www.bkjia.com;

Root/data/bbs;

}

Test the verification result using curl or enter the domain name in the browser for access;

# Curl 192.168.22.20

This is bkjia linux

# Curl 192.168.22.21

This is bkjia bbs

For more Nginx tutorials, see the following:

Deployment of Nginx + MySQL + PHP in CentOS 6.2

Build a WEB server using Nginx

Build a Web server based on Linux6.3 + Nginx1.2 + PHP5 + MySQL5.5

Performance Tuning for Nginx in CentOS 6.3

Configure Nginx to load the ngx_pagespeed module in CentOS 6.3

Install and configure Nginx + Pcre + php-fpm in CentOS 6.4

Nginx installation and configuration instructions

Nginx log filtering using ngx_log_if does not record specific logs

Nginx details: click here
Nginx: click here

This article permanently updates the link address:

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.