Note: Installation Process of ubuntu & debian almost same. but we have to choose distribution code.
also follow lemp installation process
Mainline or stable nginx (we choose mainline for latest features as well security updates)
stable only security updates (recommended long term deployments maybe)
Easy Method 1 : Installing Prebuilt Debian Packages
sudo apt-get update && sudo apt-get install nginx
check nginx version
nginx -V
sudo nginx -v
nginx version: nginx/1.6.2
nginx version: nginx/1.18.0 (Ubuntu) some old version form ubuntu repository if you wanr new go for below 2nd method
by the way nginx latest version from here (http://nginx.org/en/linux_packages.html)
Allow ufw firewall for nginx
- sudo ufw allow ‘Nginx HTTP’
Check Nginx status
systemctl status nginx
check your web server by IP Address
Next step: configuring nginx by Nginx.conf nginx performance tuning
Installing Prebuilt Ubuntu Packages
NGINX provides packages for the following Ubuntu operating systems:
Version Codename Supported Platforms
16.04 xenial x86_64, i386, ppc64el, aarch64/arm64
18.04 bionic x86_64, aarch64/arm64
19.10 eoan x86_64
20.04 focal x86_64, aarch64/arm64
installing nginx from Ubuntu Repository
sudo apt-get update && sudo apt-get install nginx
2. Prebuilt Ubuntu Package from the Official NGINX Repository
a.
Ubuntu
sudo apt install curl gnupg2 ca-certificates lsb-release ubuntu-keyring
Import an official nginx signing key so apt could verify the packages authenticity. Fetch the key:
curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \ | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
Verify that the downloaded file contains the proper key:
gpg --dry-run --quiet --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg
The output should contain the full fingerprint 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62
as follows:
pub rsa2048 2011-08-19 [SC] [expires: 2024-06-14] 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62 uid nginx signing key <signing-key@nginx.com>
If the fingerprint is different, remove the file.
To set up the apt repository for stable nginx packages, run the following command:
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \ http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" \ | sudo tee /etc/apt/sources.list.d/nginx.list
If you would like to use mainline nginx packages, run the following command instead:
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \ http://nginx.org/packages/mainline/ubuntu `lsb_release -cs` nginx" \ | sudo tee /etc/apt/sources.list.d/nginx.list
Set up repository pinning to prefer our packages over distribution-provided ones:
echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" \ | sudo tee /etc/apt/preferences.d/99nginx
To install nginx, run the following commands:
sudo apt update sudo apt install nginx
explained
Before installing nginx make sure to know which module need to add follow nginx modules list
https://nginx.org/en/linux_packages.html
Install the prerequisites:
sudo apt install curl gnupg2 ca-certificates lsb-release
a.Add nginx keys
sudo wget https://nginx.org/keys/nginx_signing.key
sudo apt-key add nginx_signing.key
Verify that you now have the proper key:
sudo apt-key fingerprint ABF5BD827BD9BF62
b. add nginx repository apt sources list
nano /etc/apt/sources.list
deb https://nginx.org/packages/mainline/ubuntu/ <CODENAME> nginx
deb-src https://nginx.org/packages/mainline/ubuntu/ <CODENAME> nginx
Mainline or stable
codename = replace with ubuntu 20.04 or 18.04 bionic version
mycase:
deb https://nginx.org/packages/mainline/ubuntu/ focal nginx
deb-src https://nginx.org/packages/mainline/ubuntu/ focal nginx
sudo apt-get update && sudo apt-get install nginx
check nginx installed version
nginx -V
check whether it(nginx status modules) enabled or not
nginx -V 2>&1 | grep -o with-http_stub_status_module
root@instance-1:~# nginx -v
nginx version: nginx/1.19.6 (changelog
install nginx with stub status module & Brotil
./configure
–with-http_stub_status_module
–with-compat –add-dynamic-module=../ngx_brotli
Next Follow LEMP Stack Installation Process or mysql installation ubuntu,
php -fpm installation on ubuntu
Upgrading Nginx to latest version ubuntu
by default the command
sudo apt-get install nginx installs lower version,
you can upgrade by adding new repo files from above