Home Tech How To Install the Latest Version of NGINX on APT under Debian

How To Install the Latest Version of NGINX on APT under Debian

49
0
How To Install the Latest Version of NGINX on APT under Debian
How To Install the Latest Version of NGINX on APT under Debian

Introduction

Nginx is an asynchronous framework web server that can also be used as a reverse proxy, load balancer and HTTP cache. The software was created by Igor Sysoev and first publicly released in 2004. The company of the same name was established in 2011 to provide support. Nginx is a free and open source software released under the terms of a BSD-like license.

This article describes how to apt install the latest version of Nginx by adding sources in the Debian system.

You can read this article to install PHP: APT install PHP 7.1 / 7.2 / 7.3 / 7.4 in Debian system

installation

Installation prerequisites:

sudo apt install curl gnupg2 ca-certificates lsb-release

To set up the apt repository for the stable nginx package, run the following command:

echo "deb http://nginx.org/packages/debian` lsb_release -cs` nginx "\
    | sudo tee /etc/apt/sources.list.d/nginx.list

If you want to use the mainline nginx package, run the following command instead:

echo "deb http://nginx.org/packages/mainline/debian` lsb_release -cs` nginx "\
    | sudo tee /etc/apt/sources.list.d/nginx.list

Next, import the official nginx signing key so that apt can verify the authenticity of the software package:

curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo apt-key add-

Verify that you now have the correct key:

sudo apt-key fingerprint ABF5BD827BD9BF62

The output should contain the complete fingerprint 573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62as follows:

pub rsa2048 2011-08-19 [SC] [expires: 2024-06-14]
      573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62
uid [unknown] nginx signing key <[email protected]></[email protected]>

To install nginx, run the following command:

sudo apt update
sudo apt install nginx

common problem

Installation using NGINX official source will find an error in Systemd

● nginx.service-nginx-high performance web server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2020-04-15 18:16:30 CST; 22min ago
     Docs: http://nginx.org/en/docs/
  Process: 31377 ExecStart = / usr / sbin / nginx -c /etc/nginx/nginx.conf (code = exited, status = 0 / SUCCESS)
 Main PID: 31379 (nginx)
    Tasks: 3 (limit: 1122)
   Memory: 8.4M
   CGroup: /system.slice/nginx.service
           ├─31379 nginx: master process / usr / sbin / nginx -c /etc/nginx/nginx.conf
           ├─31380 nginx: worker process
           └─31381 nginx: worker process

April 15 18:16:30 debian systemd [1]: nginx.service: Succeeded.
April 15 18:16:30 debian systemd [1]: Stopped nginx-high performance web server.
April 15 18:16:30 debian systemd [1]: Starting nginx-high performance web server ...
April 15 18:16:30 debian systemd [1]: nginx.service: Can't open PID file /run/nginx.pid (yet?) After start: No such file or directory
April 15 18:16:30 debian systemd [1]: Started nginx-high performance web server.

problem causes

This is because the PID file was not generated when the NGX was started, making the file unreadable

Solution:

In the /lib/systemd/system/nginx.serviceAdd the following statement to achieve 0.1s wait before executing the executable file 

ExecStartPost = / bin / sleep 0.1

Then reload the guardian unit

systemctl daemon-reload

Just restart nginx

service nginx restart

Reference link

  1. nginx: Linux packages
  2. nginx.service: Failed to read PID from file /run/nginx.pid: Invalid argument

LEAVE A REPLY

Please enter your comment!
Please enter your name here