How to Configure Virtual Host in NGINX Web Server

Step 1: Prerequisite

Step 2: Add Domains in nginx Configuration File

To add multiple domains in nginx web server edit /usr/share/nginx/virtual.host file and create virtual hosts.

# vi /etc/nginx/conf.d/virtual.conf
# add at the last line

server {
    listen       80;
    server_name  www.a.com;

    location / {
        root   /usr/share/nginx/a.com;
        index  index.html index.htm;
    }
}

Step 3: Restart nginx server

# mkdir /usr/share/nginx/a.com
# /etc/rc.d/init.d/nginx restart

Stopping nginx: [ OK ]
Starting nginx: [ OK ]

Step 3: Create a Web page

# vi /usr/share/nginx/a.com/index.html

<html>
<body>
<div style="width: 100%; font-weight: bold; text-align: center;">
Nginx Test Page
</div>
</body>
</html>
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *

16 − 10 =