Technology and General Blog

I have been working with Nginx as the favored internet server for most of my net projects. It is really economical than apache, which I utilised initially for my assignments. It did not take extended to uncover out the constraints of apache as the website traffic grew. 

Right after paying some time investigating remedies, at some point, I came throughout Nginx. Its efficiency and performance just amazed me. If we assess two different installations of apache and Nginx with the identical resources, Nginx would perform 10x improved in comparison to apache. That’s how a lot-optimized Nginx comes out of the box.

When I replaced Apache with Nginx as my favored world wide web server. The app was now capable to tackle hundreds of concurrent connections for every 2nd, which was beforehand not probable with apache with out expanding the server sources and also the charge.

As I tinkered with Nginx’s configurations, it grew to become more successful. In a number of months, I was hosting several internet websites on my server powered by Nginx devoid of the have to have of growing the server methods. Nginx helped me help save a great deal on web web hosting fees. 

Nginx has several other immensely beneficial features beneath its hood, which I will be masking in my guides in the coming days. In this write-up, I will show you how to host a number of sites on an Nginx server.

If you are informed, Nginx has a aspect known as digital hosts. As the name implies, this feature makes it possible for the generation of separate virtual hosts inside of a solitary server. Each and every virtual host is able of serving one website.

All the digital hosts share the sources of a solitary server. So many internet sites can be hosted on a one server as lengthy as the total resource use of the hosts stays inside the server’s allocated limit. 

For example, on a server with 1 GB of RAM and 20 GB of storage house, you can host 10 static web sites with very low to reasonable targeted traffic. The ordinary value of web hosting with the over methods should be $5. The cost of just about every virtual host arrives to $.5. The value of web hosting these 10 web sites on shared internet hosting will be a lot more.

How to Host Numerous Web-sites on a Nginx Server

Now that we know about virtual hosts on Nginx, let’s locate out how we can use virtual hosts to host several web sites on an Nginx web server. 

In advance of we carry on in advance, make certain you have pointed the domains to your internet hosting server.

I am assuming you have Nginx put in on your ubuntu server. The pursuing are illustrations of two domains for which we will create the digital hosts.


Initially of all, we need to generate the digital host for the very first area: We will build a virtual host file in the /etcetera/nginx/web-sites-available folder and enter the adhering to. For this case in point, I will name it abc. 


    hear 80
    root /residence/
    index index.html

    area / 
         attempt_files $uri $uri/ =404

Upcoming, we will have to create the digital host file for the 2nd domain: It will be particularly the exact as the to start with virtual host file. Having said that, we will have to adjust the root folder spot and the server names. I will title it xyz.


    pay attention 80
    root /residence/
    index index.html

    spot / 
         consider_files $uri $uri/ =404

We have produced the digital host file for the two domains in the web-sites-available folder. In buy to empower the domains, we will have to create a symlink for the virtual hosts in the web pages-enabled folder.

sudo ln -s /and many others/nginx/web-sites-available/abc /and so forth/nginx/web pages-enabled/abc

sudo ln -s /and so on/nginx/web sites-accessible/xyz /and so on/nginx/web-sites-enabled/xyz

As soon as we run these commands, we have to restart the Nginx server for the changes to choose spot. The subsequent code will restart the Nginx server.

sudo service nginx restart

This should make the domains dwell, provided you have already pointed the area names to the web hosting by updating the nameservers or A records.

You can now enter the domains in the browser and each area ought to load from the respective root folder. You can now go forward and set up letsencrypt to enable HTTPS on equally domains.

Leave a Reply

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