How to Use the Nginx Web Server to Host Several Websites

by | Feb 17, 2023 | Uncategorized

Several websites can be published on a same server using virtual hosting. This enables servers to share resources with the advertised services, such as memory and processor cycles. Web servers are commonly referred to by the term supplied. But, the same ideas hold true for other Internet services. Shared web hosting is one of the most often used applications. Since they can host numerous clients on one server and the costs are lower than those of a dedicated server. In the previous blog, we talked about setting up Nginx; now, we’ll look at how to use the Nginx Web Server to publish several websites.

You can use the same server resources for various sites when using the Nginx web server. Several webpages can be published by a single instance of a web server. Include it in the conf file along with your VPS’s IP address and URL. The document root will manage the traffic after the request has been made.

Use the Nginx Web Server to Run Several Websites

So, in this manual, we’ll explain how to host numerous domains on a single server by using server blocks to encapsulate configuration information. We’ll create the domain On Ubuntu 20.04, Nginx has a server block set up by default to serve files from directories under /var/www/html. When hosting numerous sites, this might become cumbersome even though it works great for one site. We will establish the directory structure for the site within /var/www and set /var/www/ as the default directory to be served rather than changing /var/www/html.

First, use the supplied command to establish a directory for so that any requests for will be fulfilled from the /var/www/ directory.

 # mkdir -p /var/www/

Next, we’ll use vi or your preferred editor to construct an index.html page. Execute the aforementioned terminal command.

# vi /var/www/html/

Then, open the file using the provided command and save it with:wq.

<title></title> <h1>Welcome to!</h1</html>

Then, use the provided command to add the following to the Nginx.conf file.

# vi /etc/nginx/nginx.conf

Save the .conf file.

server {
listen 80;
root /var/www/html/;
index index.html;
location / {
try_files $uri $uri/ =404;

The website will now be accessible on port 80 by the Nginx Server. By using the provided command at the terminal, you may examine the conf file for any syntax errors.

# nginx -t

After that, use the provided command to restart the server. Then, to access the index page, open your web browser and type

# systemctl restart nginx


Simply said, you may use the server resources more effectively with virtual hosting. For your website, a VPS server offers a composite virtual host. Unlimited company websites can be hosted on a single server. Respond to inquiries from specified URLs. The procedures for using the Nginx web server to host numerous websites were covered in this tutorial. Apache may be used for this as well.

Read Our Next Articles Introducing Four New ISP Provider With Residental-VPS