• Contact
  • Contact Us
  • Disclamer
  • Home 1
  • Home 2
  • Home 3
  • Privacy Policy
Friday, May 9, 2025
How VPS - How to use/setup VPS
  • Login
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
How VPS - How to use/setup VPS
No Result
View All Result
Home Control Panels

How to configure Nginx Server Blocks on a Debian 9 VPS or Dedicated Server

How VPS by How VPS
November 2, 2018
in Control Panels
0
How to configure Nginx Server Blocks on a Debian 9 VPS or Dedicated Server
0
SHARES
27
VIEWS
Share on FacebookShare on Twitter

Contents

  1. Introduction
  2. Before you Start
  3. Step 1 – Creating A Document Structure
  4. Step 2 – Creating A Nginx Server Block
  5. Conclusion
  6. Check out these top 3 Best web hosting services
    1. Was this article helpful?

Introduction

Nginx Server Blocks enable web administrators to run multiple websites on one VPS or dedicated server.

The server blocks allow you to encapsulate web configuration details, making it easy to utilize different SSL certificates, create a unique security policy, and stipulate the document root for each website.

This tutorial will help you configure the Nginx Server Blocks on your Debian 9 server.

Before you Start

For this tutorial to flow seamlessly, you require the following:

  • Nginx installed on your Debian 9 server at a service that supports Linux hosting
  • A domain pointing to the Debian server. We’ll utilize example.com as the domain name in our tutorial; remember to replace this name with your unique domain name.

If everything is in place, let’s get started!

Step 1 – Creating A Document Structure

The first thing when setting up Nginx server blocks is creating a directory structure (document root). The document root is a location where your domain’s web files are store and presented upon any request. Feel free to structure your document root (main directory) to be on any location on your system.

In our tutorial we’ll have the structure below for the root directory:

/var/www/
├── domain1.com
│   └── public_html
├── domain2.com
│   └── public_html
├── domain3.com
│   └── public_html

If you are hosting multiple domains, you should come up with a distinct directory structure for each of the domain. Here, we will create a root directory for the domain name and host it on the directory,  /var/www. That is, We will create a directory called public_html, within the main directory, /var/www. The public_html is a directory used to store the website files for each of the domain.

Log in to your Debian 9 server and issue the command below:

$ sudo mkdir -p /var/www/example.com/public_html

The command above will create a directory, public_html for the domain example.com in the main directory, /var/www.

Next, run the command below to create a file called index.html that is hosted in the directory  public_html.

$ sudo nano /var/www/example.com/public_html/index.html

Copy and add the lines below into this file:

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>Welcome to example.com</title>
  </head>
  <body>
    <h1>Success! example.com home page!</h1>
  </body>
</html>

Save the changes and exit the text editor.

Now, issue the command below to transfer your document root’s ownership to a www-data (Nginx User). This prevents the occurrence of permission issues:

$ sudo chown -R www-data: /var/www/example.com

Step 2 – Creating A Nginx Server Block

Debian 9 system stores the configuration files for Nginx server blocks in the directory, /etc/nginx/sites-available. These configuration files are enabled to another directory /etc/nginx/sites-enabled/, via symbolic links.

To create a file for the Nginx Server Block, issue the command below

$ sudo nano /etc/nginx/sites-available/example.com.conf

Copy and add the content below into the file:

server {
    listen80;
    listen [::]:80;

    root /var/www/example.com/public_html;

    index index.html;

    server_name example.com www.example.com;

     access_log /var/log/nginx/example.com.access.log;
     error_log /var/log/nginx/example.com.error.log;

    location / {
        try_files$uri$uri/ =404;
    }
}

Save the changes and exit the text editor.

Note: we’ve used example.com.conf as the name for our configuration file. You can give this file a different name, but it’s advisable you use your domain as the name for the file.

By now, the configuration file is ready but it’s enabled. To enable this file, execute the command below:

$ sudo ln -s /etc/nginx/sites-available/example.com.conf /etc/nginx/sites-enabled/

Next, run the command below to confirm if the format for this configuration file is correct:

$ sudo nginx -t

If everything was implemented successfully, you will get an output similar to the one below:

nginx: the configuration file /etc/nginx/nginx.confsyntax is ok
nginx: configuration file /etc/nginx/nginx.conftest is successful

Now, issue the command below to restart Nginx and implement the changes made:

$ sudo systemctl restart nginx

To check if the new server block is functioning properly, open your website using your favorite browser. If the server block is running correctly, you will get this message:

How to configure Nginx Server Blocks on a Debian 9 VPS or Dedicated Server

Conclusion

That is it! You have successfully created and configured a Nginx Server Block on your Debian 9 server. Follow the steps above to set up a server block for each of the other domains.

Check out these top 3 Best web hosting services

0

Was this article helpful?

Submit
Previous Post

15 Tips On How to Use ‘Curl’ Command in Linux

Next Post

fswatch – Monitors Files and Directory Changes or Modifications in Linux

Next Post

fswatch – Monitors Files and Directory Changes or Modifications in Linux

Leave a Reply Cancel reply

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

No Result
View All Result

Recent Post

Install Imagemagick on CentOS
CentOS

Install Imagemagick on CentOS

by How VPS
June 28, 2023
0

This is how I installed Imagemagick on a vanilla CentOS server Start off by installing the prerequisites yum install php-pear...

Read more
how to Check phpinfo

How to Check phpinfo of Hosting or VPS?

June 28, 2023
Failed to download metadata for repo 'appstream' on Centos 8

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

February 25, 2022
How to Fix MySQL Error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed"?

How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”?

November 17, 2020
How to optimize Mysql or MariaDB

How to optimize Mysql or MariaDB

November 3, 2020

Recent News

  • Install Imagemagick on CentOS
  • How to Check phpinfo of Hosting or VPS?
  • How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

Category

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel
  • About
  • Advertise
  • Careers
  • Contact

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Thabet