Nginx installation in the LNMP environment has been introduced, configuration files in the installation directory under the Conf subdirectory, mainly divided into four parts: main (Global Settings), Server (host settings), upstream (Load balancer server settings), Location (URL matches settings at a specific position). Can be narrowly understood that a server is a virtual host. There are three main ways to configure a virtual host: domain-based, port-based, IP-based. The following are respectively described:
First, based on the domain name:
Main steps: 1. First add the domain name resolution for the virtual machine IP address in the Windows Local hosts
192.168.1.104 z.com
2. New index.html file in the corresponding domain name website directory
3. Modify the nginx.conf configuration file to add the following information to save exit
server {
Listen 80;
server_name z.com;#
Location/{
Root z.com; #相对路径 nginx installation directory
Index index.html;
}
}
4. Detect configuration information #/app/local/nginx/sbin/nginx-t successful prompt successful
5. Restart Nginx #/app/local/nginx/sbin/nginx-s Reload
6. Enter domain name access via the Curl command or browser
# curl-xlocalhost:80 Z.com
This is z.com
Second, Port-based: Use port to differentiate, browser use domain name or IP address: port number to access
Main steps: 1. Create a new directory Mkdir/var/tmp/www and create a new index.html file in this directory to add
Welcome to Z.com ' Spanel
2. Modify the nginx.conf configuration file to add the following information to save exit
server {
Listen 2022;
server_name localhost;
Location/{
root/var/tmp/www;
Index index.html;
}
}
3. Detect configuration information #/app/local/nginx/sbin/nginx-t successful prompt successful
4. Restart Nginx #/app/local/nginx/sbin/nginx-s Reload
5. Enter domain name access via the Curl command or browser
# Curl http://192.168.1.104:2022
Welcome to Z.com ' Spanel
Third, IP-based
Main steps: 1. Add IP Address
#ifconfig |grep "inet addr"
inet addr:192.168.1.104 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
# ifconfig |grep "inet addr"
inet addr:192.168.1.104 bcast:192.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 addr:127.0.0.1 mask:255.0.0.0
2. Create a new directory MKDIR/APP/LOCAL/NGINX/HTML/IP and create a new index.html file in this directory to add
The From IP
3. Modify the nginx.conf configuration file to add the following information to save exit
server {
Listen 80;
server_name 192.168.1.220;
Location/{
Root HTML/IP;
Index index.html;
}
}
4. Detect configuration information #/app/local/nginx/sbin/nginx-t successful prompt successful
5. Restart Nginx #/app/local/nginx/sbin/nginx-s Reload
6. Enter domain name access via the Curl command or browser
# Curl HTTP://192.168.1.220
The From IP
Nginx Virtual Host Configuration summary