In order for each server to provide more users, a server can be divided into a number of sub-servers through virtualization technology, each of which is independent of each other. We call the server a virtual host. After we have set up the Nginx server, we can split a NGIXN server into multiple separate sub-servers. There are a few steps to configuring a virtual host in Nginx:
1. Configure the IP address
2. Bind the IP address to the virtual host
I. Configuring IP Addresses
Configure IP Address:
ifconfig192.168.1.102255.255.255.0
Configure sub-device 1:
ifconfig eth0:1192.168.1.103192.168.1.255255.255.255.0
Configure sub-device 2:
ifconfig eth0:2192.168.1.104192.168.1.255255.255.255.0
Two. Configuration of the virtual host
After configuring the IP address, connect the corresponding IP address with the virtual host for that, which is called the virtual host configuration.
Build the Ngixn profile in the/usr/local/nginx/conf/directory: virtualhost.conf, and configure it.
Such as:
User pi; Worker_processes4; events{worker_connections1024x768; HTTP {server {}}Listen 192.168.1.103: the; server_name192.168.1.103; Access_log/logs/server1.access.Log; Location/{Index Index. htmlIndex. htm; Root Html/server1; }} server {Listen 192.168.1.104: the; server_name192.168.1.104; Access_log/logs/server2.access.Log; Location/{Index Index. htmlIndex. htm; Root Html/ss2; } } }
3 Create directory Server1 and SS2 under the/usr/local/html directory, and create index.html files in two directories,
/server1/index.html file content is test ...
/ss2/index.html file content is test SS2 ...
4. Start the service
/usr/local-c /usr/local/nginx/conf/virtualhost.conf
5. In the browser access: http://192.168.1.103/
Discovery Browser Returns test ...
Access in Browser: http://192.168.1.104/
Discover browser return test SS2 ...
Nginx Virtual Host configuration