Configure virtual hosts in nginx

Source: Internet
Author: User

What is a VM:

Using software and hardware technology, a host is divided into one "virtual" host, each host has an independent website, domain name

Nginx virtual host type:

  1. IP-based

  2. Based on Domain Name

  3. Port-based

    Add two ip aliases in eth0

Ifconfig eth0: 1 192.168.22.11 broadcast192.168.22.255 netmask 255.255.255.0

Route add-host 192.168.22.11 Dev eth0: 1

Ifconfig eth0: 2 192.168.22.12 broadcast192.168.22.255 netmask 255.255.255.0

Route add-host 192.168.22.12 Dev eth0: 2

Note: ifconfig

This command can be manually started, observed, and set network interface parameters.

Format: ifconfig interface [Options]

Interface: network interfaces, such as eth0, eth1, and ppp0;

Options parameters that can be set:

Up | down: Enables or disables network interfaces.

Netmask: Subnet Mask

Broadcast: broadcast address

MTU: Maximum Transmission Unit (byte)

Note: ifconfig eth0: 0 [IP] indicates setting another simulated network interface on the network interface.

Route

1. # route [-nee]

This command is used to query route information.

-N: no communication protocol or host name is used, and route information is directly displayed using IP address or port number.

(This method shows the route information quickly)

-Ee uses more detailed information for display.

2. # route add | del [-net |-host] [network segment or host] netmask [mask] [GW | Dev]

Add or delete route Parameters

Netmask, which is related to the CIDR block. Setting the netmask value can determine the size of the CIDR block.

GW, abbreviated as gateway

Dev specifies that the NIC is online and then connected to eth0.

Add the last two sentences to/etc/rc. Local startup.

Modify the nginx configuration file nginx. conf in/etc/nginx. conf.

  • IP-based

Server {

# Listening IP Port

Listen 192.168.22.11: 80;

# Host Name

SERVER_NAME 192.168.22.11;

# Charset koi8-r;

# Path for storing access log files

# Access_log logs/server1.access. Log main;

Location /{

# Directory for storing webpage files

Root/usr/share/nginx/html/server1;

# Default homepage file, from left to right

Index index.html index.htm index. php;

}

Error_page 404/404 .html;

Location =/404.html {

Root/usr/share/nginx/html;

}

Other virtual hosts are configured according to this, and each server {........} Represents a virtual host

  • Based on Domain Name

Server {

# Listening IP Port

Listen 80;

# Host Name

SERVER_NAME www.xxoo.com xxoo.com * .xxoo.com;

# Charset koi8-r;

# Path for storing access log files

# Access_log logs/xxoo. Access. Log main;

Location /{

# Directory for storing webpage files

Root/usr/share/nginx/html/server1;

# Default homepage file, from left to right

Index index.html index.htm index. php;

}

Error_page 404/404 .html;

Location =/404.html {

Root/usr/share/nginx/html;

}


This article from the "gentleman not" blog, please be sure to keep this source http://leozee.blog.51cto.com/4356026/1547905

Configure virtual hosts in 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.