How to Install Nginx on Debian 8/9/10

Nginx is an open-source, high-performance HTTP and reverse proxy server that powers some of the largest sites on the Internet and can easily be installed on the Linux platform.

Nginx is a high performance webserver as a replacement for Apache.Nginx can handle a much large number of concurrent connections and has a smaller memory footprint per connection.

In this tutorial, we’ll show how to install and manage Nginx on Debian 8/9/10.

Step 1. Install Nginx on Debian

The Nginx package is included in the default Debian Buster repositories. So a few commands can complete the Nginx installation.

The installing is very easy,just run the following commands as root or user with sudo privileges:

sudo apt update
sudo apt install nginx

Nginx service will automatically start after the installaing process is complete.Run the follow command to verify it.

curl -I 127.0.0.1

The output will look somting like the follow:

HTTP/1.1 200 OK
Server: nginx/1.14.2
Date: Tue, 18 Jul 2019 10:20:41 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 18 Jul 2019 10:20:41 GMT
Connection: keep-alive
ETag: "5d2e0052-264"
Accept-Ranges: bytes

The Nginx server is now installed and running.

Step 2. Manage the Nginx Server

You can use the systemctl command to manage the Nginx service.

Start and enable Nginx with the following commands:

sudo systemctl start nginx
sudo systemctl enable nginx

Stop, restart and reload Nginx with the following commands:

sudo systemctl stop nginx
sudo systemctl restart nginx
sudo systemctl reload nginx

To view the Nginx server status,type the following command which will print the service status:

sudo systemctl status nginx

If you make changes to the Nginx server’s configuration file,Use the following command to test the Nginx configuration for any syntax or system errors:

sudo nginx -t

To check Nginx version ,type the following command:

sudo nginx -v

Step 3. Adjust the Firewall

UFW users can open HTTP (80) and HTTPS (443) ports by enabling the ‘Nginx Full’ profile:

sudo ufw allow 'Nginx Full'

If you are using nftables to filter connections to your system, open the necessary ports by issuing the following command:

nft add rule inet filter input tcp dport {80, 443} ct state new,established counter accept

Conclusion

Installing Nginx on Debian 8/9/10 is a matter of running a single command.

Now that you have installed Nginx on your Debian Linux distribute, you can to start deploying your applications and use Nginx as a web or proxy server.

If you have any question or feedback, feel free to leave a comment.

Leave a Reply