How to Install Nginx on Debian 10

Table of Contents
Installing Nginx On Debian 10
Nginx is one of the best free, opensource and High-performance web server available today. It is used as a reverse proxy web server for Apache and other web servers. Nginx can handle the bigger amount of connection than apache consuming low memory power. So it can be used for high traffic websites. In this tutorial, you are going to learn how to install Nginx on Debian 10.
Prerequisites
Before you start to install Nginx on Debian 10. You must have the non-root user account on your server with sudo privileges.
1. Install Nginx on Debian
Here first you will need to update the package manager index and then you will install Nginx.
Update package manager index by typing
sudo apt update
Now install Nginx by typing
sudo apt install nginx
Nginx web server automatically starts after installation complete. To check the status of Nginx server and confirm installation type following in the terminal
sudo systemctl status nginx
The output should be:
● nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled) Active: active (running) since Sat 2018-10-22 11:44:12 CDT; 4min 10s ago Docs: man:nginx(8) Process: 6412 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS) Process: 6409 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS) Main PID: 6413 (nginx) CGroup: /system.slice/nginx.service ├─6413 nginx: master process /usr/sbin/nginx -g daemon on; master_process on; ├─6414 nginx: worker process └─6415 nginx: worker process
2. Managing Nginx web server
There are some useful commands using **systemctl** you can manage your Nginx web server easily.
Make it sure Nginx started on system reboot by typing
sudo systemctl enable nginx
If you want to disable automatic startup on system reboot enter following command
sudo systemctl disable nginx
To check the status on Nginx enter the following command
sudo systemctl status nginx
You can start server by typing
sudo systemctl start nginx
You can stop Nginx server using the following command
sudo systemctl stop nginx
In case, If you want to restart Nginx server type following command
sudo systemctl restart nginx
3. Set up Nginx configuration file
Now you should create a directory inside var/www named example.com (you can also use your domain name)
sudo mkdir -p /var/www/example.com
Now you should remove the default configuration file provided. Delete default Nginx configuration file by typing.
sudo rm -f /etc/nginx/sites-enabled/default
Configuration files for the website are stored inside /etc/nginx/sites-available directory so you need to create configuration file inside this directory named example.com.conf. Then enter following code inside the file by replacing example.com with your domain name.
/etc/nginx/sites-available/example.com.conf server { listen 80 default_server; listen [::]:80 default_server; server_name example.com www.example.com; root /var/www/html/example.com; index index.html; location / { try_files $uri $uri/ =404; } }
Create a symbolic link of the above configuration file inside /etc/nginx/sites-enabled/ directory by entering
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
Now you will need to reload Nginx configuration file as you have made changes in Nginx configuration directory. Type following command to reload Nginx
sudo nginx -s reload
You can check the status of Nginx by typing following
sudo nginx -t
Create an index.html file inside /var/www/example.com directory and enter following code inside the file
<html> <head> <title>Index Page</title> </head> <body> <h1>Success!</h1> </body> </html>
Now visit (http://example.com). Replacing example with your domain name where you can see the output as given: ==Success!==
Conclusion
You have successfully learned how to install Nginx on Debian 10. If you have any queries regarding this please don’t forget to comment below.
LATEST POSTS
-
How to Use Linux Screen Command With Examples
-
How to install LAMP stack on Debian 9
-
How to Install CMake on Ubuntu 18.04
-
How to Install Gradle on Ubuntu 18.04
-
How to Install Minecraft on Linux Mint 19
-
How to Change Hostname on Ubuntu 18.04
-
How to install MariaDB 10 on Debian 9
-
How to Set or Change User Password in Linux
-
How to Install Postman on Debian 10
-
How to Stop and Disable FirewallD on CentOS 8
-
How to install Composer on Ubuntu 18.04
-
How to Install MariaDB on Fedora 29