How to host multiple webites on Nginx

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

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

abc.com
cde.com
efg.com
Comment
Watch Question

Do more with

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

/var/www/abc.com/public_html

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

For example: /etc/nginx/sites-available/abc.com

In each file you set a config similar to this:

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

        root /var/www/abc.com/public_html;
        index index.html index.htm;

        server_name abc.com;
}

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/abc.com /etc/nginx/sites-enabled/abc.com
sudo ln -s /etc/nginx/sites-available/cde.com /etc/nginx/sites-enabled/cde.com
sudo ln -s /etc/nginx/sites-available/efg.com /etc/nginx/sites-enabled/efg.com

Restart nginx.

Author

Commented:
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

Commented:
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