Nginx is a very popular high-performance web server that combines the power of reverse proxying, load balancing, caching and so much more. Depending on how it is configured, it can act as a reverse proxy as well as a load balancer for HTTP/HTTPS servers.
Nginx web server has a phenomenal capability in serving thousands of concurrent connections and this makes it the fastest web server, powering over half of the busiest sites on the globe. These include Netflix, DuckDuckGo, and DropBox to mention just a few.
Read Also: How to Install Apache with Virtual Hosts on Debian 10
In this tutorial, we will walk you through the steps on how to install Nginx with virtual hosts to host multiple domains on a on Debian 10 server.
Prerequisites
Before we get started, ensure the following requirements are met:
- An instance of Debian 10.
- A Fully Qualified Domain Name (FQDN) pointing to the server.
- In this guide, we use the domain
tecmint.com
pointing to a Debian 10 system with an IP address 192.168.0.104. - A good internet connection.
Step 1: Update the Debian 10 Package Repository
Before anything else, we need to update our local package repository to the latest versions. To achieve this, log in as a regular user with sudo privileges and run the command below.
$ sudo apt update -y

Step 2: Install Nginx on Debian 10
Since Nginx is present in Debian’s repositories, we can comfortably go ahead and install it using the apt package manager that comes with Debian.
$ sudo apt install nginx -y

Step 3: Checking the Status of Nginx Webserver
If you encountered no errors, then Nginx web server was successfully installed. It’s prudent to verify the status of the web server before making further configurations.
To check the status of Nginx, execute:
$ systemctl status nginx
If the web server is up and running, you’ll get the notification below.

If you wish to restart the Nginx web server, run the command.
$ systemctl restart nginx
To stop Nginx, issue the command.
$ systemctl stop nginx
To start the web server, run.
$ systemctl start nginx
To configure Nginx web server to start on boot run.
$ systemctl enable nginx
Read Also: 10 Most Used Nginx Commands Every Linux User Must Know
Step 4: Configure the Firewall to Open Nginx Port
With Nginx successfully installed and running, we need to allow web access to the service, especially to external users. If you have UFW firewall enabled, you need to allow HTTP access through the firewall.
To achieve this, execute the command.
$ sudo ufw allow 'Nginx HTTP'
Next, reload the firewall to effect the changes.
$ sudo ufw reload
Great, now you can verify that HTTP is allowed through the firewall by running.
$ sudo ufw status

From the snippet above, we can clearly see that Nginx HTTP has been allowed through the UFW firewall.
Step 5: Accessing Nginx Web Server
We have so far made the basic configurations to get Nginx up and running. To access the web server via the web browser, browse the server’s IP address as shown.
http://server-IP-address

This is a confirmation that Nginx is up and running.
Step 6: Configuring Nginx Server Blocks on Debian 10
This is an optional step and is useful when you want to host multiple domains on a Nginx web server. For this to work, you need to have a domain name pointed to your Debian server.
For this section, we shall use the domain name tecmint.com
who’s A
record is pointed to the server’s IP 192.168.0.104.
When you point the domain name to your server’s IP address, the domain name will soon change and point to your web server as shown.

Let’s now create a server block.
Firstly, let’s create a directory for our domain as shown.
$ sudo mkdir -p /var/www/html/tecmint.com
Then assign the required file ownership as shown.
$ sudo chown -R $USER:$USER /var/www/html/tecmint.com
Next, assign read and execute permissions to group and the public users as shown.
$ sudo chmod -R 755 /var/www/html/tecmint.com
Let’s now create a simple index.html
sample webpage using vim text editor.
$ sudo vim /var/www/html/tecmint.com/index.html
Add some sample content to the file. This will be displayed on the browser.
<html> <head> <title>Welcome to Linux geeks</title> </head> <body> <h1>Success! Welcome to your new server block on Tecmint Nginx Web Server !</h1> </body> </html>
Save and exit the editor
For this content to be served, a server block needs to be created.
Let’s create a server block
$ vim /etc/nginx/sites-available/tecmint.com
Copy and paste the following content into the server block file.
server { listen 80; listen [::]:80; root /var/www/html/tecmint.com; index index.html index.htm index.nginx-debian.html; server_name tecmint.com www.tecmint.com; location / { try_files $uri $uri/ =404; } }
Be sure to update the domain name tecmint.com with your own domain name.
To activate or enable the server block file, create a symbolic link as shown.
$ sudo ln -s /etc/nginx/sites-available/tecmint.com /etc/nginx/sites-enabled/
To verify that all settings in Nginx are properly configured, run.
$ sudo nginx -t
Great, we are good to go! Finally restart Nginx.
$ sudo systemctl restart nginx
Head out to your browser and refresh and if all went well, the browser should be serving your server block web page as shown.

Step 7: Accessing Nginx Log Files
To access log files about requests made to your server, access the file below.
$ sudo vim /var/log/nginx/access.log
In case you bump into errors in your Nginx web server, examine the file for errors.
$ sudo vim /var/log/nginx/error.log
Conclusion
In this guide, you learned how to install Nginx on your Debian 10 instance and configuring it further to support additional domains. We hope you found this guide insightful. Your feedback will be appreciated..
Great article between, good job man but why use
vim
to view the logs?