Nginx Virtual Host Configuration

Source: Internet
Author: User
Tags create directory nginx server

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

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.