Upgrading Nginx to 1.30.7 on Ubuntu to Mitigate Security Vulnerabilities

Hello, this is Lovefield.

When managing production web servers, newly disclosed security vulnerabilities (CVEs) occasionally require urgent package upgrades. Recently, a vulnerability advisory made it necessary to patch our Ubuntu servers to Nginx 1.30.7 or higher.

However, simply running sudo apt upgrade nginx on Ubuntu often fails to pull the latest upstream patch release. In this post, we will examine why default Ubuntu repositories lag behind and walk through the exact steps to configure the official Nginx repository and install version 1.30.7 safely.

Why Doesn't Ubuntu's Default Repository Have the Latest Nginx?

Ubuntu's default APT repositories (archive.ubuntu.com) freeze major and minor package versions at the time of the OS release (such as Ubuntu 22.04 Jammy Jellyfish) and primarily deliver backported security fixes rather than upstream version bumps.

To install a specific upstream patch release like 1.30.7, you need to register the official Nginx package repository (nginx.org) in your APT sources.

Checking Available Versions

First, inspect which versions of Nginx are currently visible in your server's APT cache:

Shell

1

2

sudo apt update
apt-cache madison nginx

If 1.30.7 does not appear in the output list, proceed with adding the official repository below.

Pre-Upgrade Backup and Inspection

Before replacing core web server packages in production, always back up your existing configuration directory and check compiled modules:

Shell

1

2

3

4

5

# Back up the entire /etc/nginx configuration directory
sudo cp -r /etc/nginx /etc/nginx.backup.$(date +%Y%m%d)

# Inspect current build flags and loaded modules
sudo nginx -V

> Note: If you previously relied on third-party dynamic modules bundled with Ubuntu's nginx-full or nginx-extras packages, verify module compatibility under /usr/lib/nginx/modules before switching to the official nginx package.

Adding the Official Nginx Repository & Installing 1.30.7

Install Prerequisite Packages

Install the required utilities for HTTPS repository access and GPG key verification:

Shell

1

sudo apt install -y curl gnupg2 ca-certificates lsb-release ubuntu-keyring

Import the Official Nginx GPG Signing Key

Download the official signing key and store it under /usr/share/keyrings/ to verify package authenticity (using the official key endpoint https://nginx.org/keys/nginx_signing.key):

Shell

1

2

curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo gpg --dearmor \
    -o /usr/share/keyrings/nginx-archive-keyring.gpg

Add the Nginx Repository to APT Sources

Append the official repository URL matching your Ubuntu release codename (lsb_release -cs, e.g., jammy):

Shell

1

2

3

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

(Optional) Configure APT pinning so packages from nginx.org always take precedence over Ubuntu's default repository:

Shell

1

2

echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" \
    | sudo tee /etc/apt/preferences.d/99nginx

Refresh Package Lists and Install Nginx 1.30.7

Update your APT index and explicitly install version 1.30.7 (example shown for Ubuntu 22.04 Jammy):

Shell

1

2

sudo apt update
sudo apt install -y nginx=1.30.7-1~jammy

> Tip: During installation, APT may prompt you whether to overwrite /etc/nginx/nginx.conf with the package maintainer's version. Select keep the local version currently installed (N) to preserve your existing reverse proxy and SSL settings.

Verification and Service Restart

Once installation finishes, verify the binary version, test configuration syntax, and restart the service:

Shell

1

2

3

4

5

6

7

8

9

# 1. Confirm the upgraded version (should output nginx/1.30.7)
nginx -v

# 2. Validate existing configuration syntax
sudo nginx -t

# 3. Restart Nginx and check service status
sudo systemctl restart nginx
sudo systemctl status nginx

Holding the Package Version (Optional)

If your infrastructure policy requires pinning Nginx strictly to 1.30.7 to prevent unintended automatic upgrades, lock the package with apt-mark:

Shell

1

sudo apt-mark hold nginx

Summary

While applying security patches promptly is critical, doing so predictably—by backing up configurations, pinning the official upstream repository, and specifying exact target versions—prevents unexpected production downtime. Hopefully, this walkthrough helps streamline your Nginx security upgrade workflow.

This article was generated by AI.

Lovefield

Web Front-End developer

하고싶은게 많고, 나만의 서비스를 만들고 싶은 변태스러운 개발자입니다.

Complete Guide to Creating a Spring Boot 4 Project: JetBrains (IntelliJ) vs. Non-JetBrains (VS Code) Setups

A practical walkthrough for bootstrapping a Spring Boot 4.x project on Java 25 tailored to your IDE—comparing IntelliJ IDEA Ultimate's built-in wizard with Spring Initializr and Extension Packs for VS Code and Community Edition users.

Spring Boot

v5.0