Nginx is a free, high performance and open-source HTTP and reverse proxy server. It can be used as a standalone web server, and as a reverse proxy for Apache and other web servers. It is a more flexible and lightweight program than Apache HTTP Server that's why it powers some of the largest sites on the Internet.
Nginx can handle the bigger amount of connection than Apache and consuming smaller memory.
Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related Nginx queries.
In this context, we shall look into how to install Nginx on Debian 9 server.
Before proceeding with this Installation procedure, ensure that the following Prerequisites is met:
Now, update the system packages index to the latest version by executing the command:
$ sudo apt update
Now install Nginx by typing:
$ sudo apt install nginx
Once the installation process will completed, Nginx service will start automatically. You can verify it by running the following command:
$ sudo systemctl status nginx
Output
● 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 Mon 2019-04-15 20:19:06 IST; 32min ago
Docs: man:nginx(8)
Process: 421 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 370 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 423 (nginx)
Tasks: 2 (limit: 4915)
CGroup: /system.slice/nginx.service
├─423 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
└─424 nginx: worker process
If on your server firewall is enabled then you need to open both HTTP(80) and HTTPS(443) ports.
Execute the following commands to open both HTTP(80) and HTTPS(443) ports:
$ sudo firewall-cmd --permanent --zone=public --add-service=http
$ sudo firewall-cmd --permanent --zone=public --add-service=https
$ sudo firewall-cmd --reload
If your using iptables to filter connections to your system, you'll need to open HTTP (80) and HTTPS (443) ports.
Open the necessary ports by issuing the following command:
$ sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
$ sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT
You can verify your Nginx installation by visiting below URL in your browser:
http://YOUR_SERVER_IP_ADDRESS
Now, you will see the default Nginx welcome page.
Finally, you installed Nginx HTTP server on your machine. Below are few basic commands to manage Nginx service:
You can stop Nginx service execute below command:
$ sudo systemctl stop nginx
To start it again by typing:
$ sudo systemctl start nginx
Restart (stop and start) Nginx service the Apache service by:
$ sudo systemctl restart nginx
If configuration file edited and want to Reload nginx service then you can do it by typing:
$ sudo systemctl reload nginx
For disable Nginx to auto start after boot execute below command:
$ sudo systemctl disable nginx
Again to do re-enable type:
$ sudo systemctl enable nginx
/var/log/nginx/access.log: Every request to your web server is recorded in this log file unless Nginx is configured to do otherwise.
/var/log/nginx/error.log: Any Nginx errors will be recorded in this log.
This article covers how to install Nginx on your Debian 9 server. Now you can deploy your applications and use Nginx as a web or proxy server. Nginx is more resource-friendly than Apache in most cases and can be used as a web server or reverse proxy.
To install Nginx on Debian:
1. Update our local package index so that we have access to the most recent package listings:
$ sudo apt update
2. We can now install nginx:
$ sudo apt install nginx
When prompted to confirm the installation, hit Enter to proceed. After that, apt will install Nginx and any required dependencies to your server.
Profiles available for Nginx: