How to host multiple webites on Nginx

sivaatluri used Ask the Experts™
Would like to host multiple websites on Nginx Servers.

Take for example below domains should be hosted on single nginx server
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Cloud Architect
Put your sites under /var/www/, example:


Create virtual host files for each website under /etc/nginx/sites-available/

For example: /etc/nginx/sites-available/

In each file you set a config similar to this:

 server {
        listen   80; 
        #listen   [::]:80 default ipv6only=on; 

        root /var/www/;
        index index.html index.htm;


Open in new window

Repeat for all websites but replace the website name and folder name naturally...

Now for each virtual host you create make a link to sites-enabled:

sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/
sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/
sudo ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/

Restart nginx.


Are the port numbers going to be same for all the websites...

What if I want to have each website a specific port?
Zephyr ICTCloud Architect

You can keep them the same or use different ports, your choice.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial