Create Subdomain Nginx Debian 9 Server
Understanding Subdomain
A subdomain is a subsection of a domain that a user can create to host one or more websites, usually for a specific purpose. For example, if your domain is example.com, you can create a subdomain called images.example.com or blog.example.com. You can then create separate website to host on each subdomain.
While setting up a subdomain, you need to configure DNS records and web server settings, so that the user can access the website. In this article, we will discuss how to create a subdomain in a Nginx web server on Debian 9.
Prerequisites
To complete this tutorial, you will need the following:
- A Debian 9 server with Nginx installed
- A domain name (e.g. example.com)
- Root access to the server
Step 1 – Configure DNS Records
Before you can set up a subdomain, you need to configure the DNS records to point to the IP address of your server. To do this, log in to your domain registrar and add an A record for the subdomain (e.g. blog), with the IP address of your server.
Step 2 – Create Nginx Virtual Host for Subdomain
Once you have configured the DNS records, you need to create a new virtual host. To do this, open the Nginx configuration file for your domain and create a new server block.
In the server block, add the following directives:
- server_name: This should be the full domain name of the subdomain (e.g. blog.example.com)
- Root: This should be the root directory where you want to store the files for the subdomain (e.g. /var/www/blog)
When you have finished configuring the server block, save and close the file. Then, create the root directory for the subdomain and give it the appropriate permissions.
Now, you need to restart Nginx for the changes to take effect. To do this, run the following command:
sudo systemctl restart nginx
Step 3 – Create a Website for the Subdomain
Once Nginx has been restarted, you can create a website for the subdomain. To do this, create an index.html file in the root directory for the subdomain (e.g. /var/www/blog) and add some basic HTML code. You can then test the website by opening it in a web browser.
Conclusion
In this article, we discussed how to create a subdomain in a Nginx web server on Debian 9. We showed how to configure the DNS records and Nginx virtual host for the subdomain, and how to create a website for the subdomain. We hope you now have a better understanding of how to create subdomains in Nginx on Debian 9.
FAQs
Q1: How do I set up a subdomain?
A1: To set up a subdomain, you need to configure the DNS records to point to your server, then create a virtual host for the subdomain in Nginx, and finally create a website for the subdomain.
Q2: How do I add a subdomain in Nginx?
A2: To add a subdomain in Nginx, you need to create a virtual host for the subdomain in the Nginx configuration file and restart Nginx for the changes to take effect.
Q3: How do I restart Nginx?
A3: To restart Nginx, you can run the following command: sudo systemctl restart nginx.
Thank you for reading this article. Please read other articles for more information.
Related Posts:
- Virtual Host Nginx Ubuntu 16.04 Virtual Host Nginx Ubuntu 16.04 Introduction A virtual host (also known as Virtual Private Server or VPS) is a service that allows a single physical server to host multiple websites.…
- Server Block Di Dalam Nginx Server Block Di Dalam Nginx Apa itu Server Block di dalam Nginx? Server Block di Nginx adalah yang bertanggung jawab untuk memungkinkan konfigurasi hosting website yang terpisah. Setiap server block…
- Setting Domain Ke Vps Nginx Setting Domain Ke Vps Nginx What is Nginx? Nginx is a powerful web server and popular application development platform that can be used to build efficient web applications. It was…
- Nginx Responding To Any Domain Name Nginx Responding To Any Domain Name Understanding Nginx Nginx (pronounced “Engine X”) is a free, open-source, high-performance web server designed for better performance and scalability. It is used to serve…
- Nginx Config Domain Based Root Nginx Config Domain Based Root What is Nginx Config? Nginx (pronounced “engine-x”) is a popular web server software program. It is open source, high performance and is being used by…
- 404 Not Found Htaccess Setting Nginx 1.10.3 Ubuntu 404 Not Found Htaccess Setting Nginx 1.10.3 Ubuntu What Is Htaccess Setting? The .htaccess file is a special file that is used by web servers to control how a website…
- Reinstall Nginx Ubuntu 18.04 Reinstall Nginx Ubuntu 18.04 What is Nginx? Nginx is an open source, high-performance web server application designed to serve web traffic with lightning-fast speed and robust stability. Nginx is one…
- Start Nginx Service Centos 7 Start Nginx Service Centos 7 Before You Start: Server and Requirements If you are running a website or a web application on Centos 7, chances are you will be using…
- Forward Nginx To Another Subdomain Forward Nginx To Another Subdomain What is Nginx? Nginx is an open-source, high-performance web server originally developed by Igor Sysoev. Since its initial release in 2004, Nginx has become one…
- Nginx 1.14 Create Virtual Host Nginx 1.14 Create Virtual Host Overview Virtual hosting is a process for hosting multiple websites on a single physical server and IP address. Nginx version 1.14 is the most recent…
- Debian 502 Bad Gateway Nginx Fix Debian 502 Bad Gateway Nginx Fix What is a 502 Bad Gateway Error? A 502 Bad Gateway error is an HTTP status code displayed on your computer’s web browser when…
- Setting Https Wordpress On Nginx Setting Https Wordpress On Nginx Setting Up An SSL Certificate In order to enable HTTPS on your WordPress site, you first need to add an SSL certificate. An SSL certificate…
- How To Configure Nginx Debian How To Configure Nginx Debian Introduction to Nginx Debian Nginx is a web server and reverse proxy that is used to host websites and manage incoming traffic over the world…
- Nginx Same Domain Different Port Nginx Same Domain Different Port Understanding Same Domain Different Port Concept Nginx is a powerful web server that supports different type of configurations. One of its features is its support…
- Replace Apache To Nginx Ubuntu 18 Replace Apache To Nginx Ubuntu 18 Installing Nginx Ubuntu 18 uses Nginx as its default web server, and it is pre-installed. However, if you want to use a fresh version…
- Proxy Pass To Ip Public Nginx Proxy Pass To Ip Public Nginx What Is Nginx Nginx is a web server that is used to serve webpages and content on the internet. It is known for its…
- How To Install Nginx On Debian 10 How To Install Nginx On Debian 10 Overview In this guide, we will show how to install Nginx on a Debian 10 server. Nginx (pronounced “engine-x”) is an open source…
- Site Does Not Exist A2ensite Nginx Site Does Not Exist A2ensite Nginx What Is A2ensite Nginx? A2ensite Nginx is a tool designed to enable or disable a particular Nginx site from the Apache2 configuration file. It…
- Where Default Root Folder Nginx Where Default Root Folder Nginx? What Is Nginx Nginx is an open source web server designed for high concurrency, performance and low memory consumption. The official website defines it as…
- Laravel Nginx Without Custom Domain Laravel Nginx Without Custom Domain Overview of Laravel Nginx Without Custom Domain Laravel is an open-source PHP web framework used to create powerful web applications. It is based on the…
- What If Create New File At Site-Available Nginx What If Create New File At Site-Available Nginx? What is Nginx? Nginx is an open-source HTTP server and reverse proxy, which is used to power websites such as sites, wikis,…
- Reverse Proxy Firewall Nginx Debian Tutorial Reverse Proxy Firewall Nginx Debian Tutorial Introduction to Reverse Proxying with Nginx, Debian & Firewall Reverse proxying is an important technology in distributed systems. By creating a reverse proxy server,…
- How To Open Var Www Nginx How To Open Var Www Nginx What is Var Www Nginx? Var Www Nginx is a command line program used to create and manage web pages. It is included in…
- Setup Virtual Hosts In Nginx Setup Virtual Hosts In Nginx Understanding The Virtual Hosts Concept The Virtual Hosts concept is an important part of installing Nginx. It allows you to host multiple websites on a…
- Membuat Nginx Proxy Ubuntu Lebih Dari Satu Subdomain Membuat Nginx Proxy Ubuntu Lebih Dari Satu Subdomain Apa Nginx Proxy? Nginx Proxy adalah sebuah web server dan layanan proxy. Berbeda dari web server lain seperti Apache dan Microsoft IIS,…
- 403 Forbidden Nginx Ubuntu 14.04 403 Forbidden Nginx Ubuntu 14.04 What Is a 403 Forbidden Error? A 403 Forbidden error is an HTTP status code that denotes that a server, upon receiving a request from…
- Centos 7 Nginx Letsencrypt Https And Https Centos 7 Nginx Letsencrypt Https And Https Overview Many web servers require secure communications through the HTTPS protocol, and the most common way to do this is with the help…
- Nginx Server_Name F5 Http 2 Nginx Server_Name F5 Http 2 What is Nginx Server_Name? Nginx Server_Name is a directive in the Nginx web server configuration that is used to define the websites that are served…
- Nginx Mariadb Php Fpm Debian8 Mariadb Nginx Mariadb Php Fpm Debian8 Mariadb Introduction to the Setup Nginx, MariaDB, and PHP are all popular tools for web development. Nginx is a web server, MariaDB is an open-source…
- Membuat Subdomain Di Nginx Centos 7 Membuat Subdomain Di Nginx Centos 7 Pengenalan Subdomain Subdomain adalah sub alamat yang diberikan pada url. Ini adalah alamat tambahan yang dibawa di depan alamat utama, membawa perbedaan tertentu antara…