Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
VGSources
Blog

How to Install NGINX on CentOS 8 (Stable or Mainline Repository)

A complete CentOS 8 NGINX installation guide covering the official stable repository, optional mainline channel, GPG-key verification, startup, local HTTP testing, paths, modules, and troubleshooting.
Length7 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Install NGINX on CentOS 8 by adding the official NGINX yum repository, refreshing DNF metadata, installing the nginx package, and checking the signing key before accepting it. The repository enables the stable channel by default; mainline is available as an explicit opt-in. After installation, start NGINX with sudo nginx and verify the local server with curl -I 127.0.0.1. A successful check begins with HTTP/1.1 200 OK.

What you need before installing

This procedure uses the official NGINX package repository for RHEL-based systems. NGINX documentation lists CentOS alongside RHEL, Oracle Linux, AlmaLinux, and Rocky Linux for this installation method. You need a CentOS 8 machine with a working network connection, a user that can run sudo, and enough disk space for package metadata and the installed files.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Confirm the operating system is CentOS 8.
  • Confirm your account has sudo privileges.
  • Make sure DNS and HTTPS access to nginx.org work from the server.
  • Decide whether you need the conservative stable channel or deliberately want mainline packages.

The commands below use dnf, the normal successor to yum on CentOS 8. The equivalent package instruction is often written as sudo yum install nginx; DNF is the appropriate command name for this release.

Stable or mainline: which repository should you use?

The official repository publishes two channels. Stable is enabled in the repository file and is the sensible starting point for most production servers. Mainline is an optional channel for administrators who intentionally want newer NGINX releases and are prepared to test their applications, configuration, and modules against them.

Channel Repository state in the official file Operational choice What to check
Stable Enabled by default with enabled=1 Prefer when change is tightly controlled or the server is already in production Existing configuration, dynamic modules, and application compatibility
Mainline Disabled by default with enabled=0 Use only when you specifically need the mainline stream Release freshness, module availability, upgrade behavior, and application testing

The published repository configuration does not promise identical module or compatibility behavior for every deployment. Treat the channel as an operational decision: test it in your environment before putting a change into service. Enabling mainline does not install NGINX by itself; it changes which repository DNF can use for installation or later updates.

Add the official NGINX repository

Create /etc/yum.repos.d/nginx.repo as root. The following is the repository layout published by NGINX. It enables stable and defines mainline without enabling it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
[nginx-stable]
name=nginx stable repo
baseurl=https://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=https://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

You can create the file with an editor, for example:

sudo vi /etc/yum.repos.d/nginx.repo

Paste the two stanzas exactly, save the file, and exit. The $releasever and $basearch variables are intentional: DNF substitutes the CentOS release and CPU architecture when it constructs the repository URL. Do not replace them with a guessed directory name.

The stable stanza points to https://nginx.org/packages/centos/$releasever/$basearch/. The optional mainline stanza points to https://nginx.org/packages/mainline/centos/$releasever/$basearch/. Both use GPG checking and the NGINX signing-key URL https://nginx.org/keys/nginx_signing.key.

Refresh metadata and install NGINX

Refresh package metadata before installing. This ensures DNF reads the repository definition you just added and has current package information.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Update repository metadata and installed packages:

    sudo dnf update
  2. Install the NGINX package:

    sudo dnf install nginx

DNF may ask for confirmation and may ask whether to import the repository signing key. Do not automatically accept that prompt; verify the key first as described below. If the package manager cannot reach the repository, stop and fix the repository or network problem rather than downloading an unrelated RPM from another source.

Verify the NGINX signing key before accepting it

GPG checking is enabled in both repository stanzas with gpgcheck=1. When DNF presents a signing-key prompt, inspect the fingerprint it displays and compare it character-for-character with the fingerprints published in the official NGINX installation guide. Accept the key only when the displayed fingerprint matches an official fingerprint.

  1. Read the complete fingerprint shown by DNF, including every hexadecimal character.
  2. Open the official NGINX installation guidance through a trusted administrative workstation or your approved documentation copy.
  3. Compare the two values exactly; do not rely on a shortened key ID or on the key’s display name alone.
  4. Decline the import if the fingerprint is missing, truncated, or different. Investigate DNS, HTTPS interception, repository-file changes, and the package-manager output before trying again.
  5. Accept the key only after the comparison succeeds, then allow DNF to continue the installation.

The key URL configured in the repository file is https://nginx.org/keys/nginx_signing.key. A URL by itself is not a substitute for checking the fingerprint presented by the package manager. The important control is the exact fingerprint comparison before trust is granted.

Install from the mainline channel instead

Leave the stable repository enabled unless you have a specific reason to use mainline. To enable mainline, run:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo dnf config-manager --enable nginx-mainline

Then install NGINX in the usual way:

sudo dnf install nginx

Because the repository file sets stable to enabled=1 and mainline to enabled=0, the stable channel remains the published default. If you enable mainline intentionally, document that choice for future upgrades and test the resulting package set with your own configuration and module inventory. Mainline should not be selected merely because its name sounds newer; the relevant question is whether the newer release is compatible with the server’s workload and extensions.

Start NGINX and verify that it answers HTTP requests

After the package installation completes, start NGINX with:

sudo nginx

Perform a local HTTP header request from the same server:

curl -I 127.0.0.1

A successful default response begins with:

HTTP/1.1 200 OK

The -I option requests headers rather than downloading the response body. Using 127.0.0.1 tests the local listener and avoids involving external DNS, a load balancer, or an Internet firewall. If you receive the expected status line, the installed NGINX process is serving the local default response.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A non-200 response still provides useful evidence: it means the request reached an HTTP listener, but the configured response or request path needs investigation. If the connection is refused or times out locally, move to the troubleshooting checks below instead of assuming the package installation failed.

Know the important files and paths

The default main configuration file is:

/etc/nginx/nginx.conf

NGINX writes its standard logs under:

/var/log/nginx/

The two primary log files are:

  • /var/log/nginx/access.log — records requests received by NGINX.
  • /var/log/nginx/error.log — records startup, configuration, connection, and runtime errors.

When a package has been built with paths that differ from the defaults, inspect its compiled configuration arguments:

nginx -V 2>&1 | awk -F: '/configure arguments/ {print $2}' | xargs -n1

This is especially useful when a command appears to succeed but the expected configuration or log file is empty. The output identifies compiled path choices so you can locate the files the installed binary actually uses.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Install a packaged dynamic module

If your configuration requires a dynamic module supplied as an NGINX package, install it by replacing <NAME> with the module’s package name:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo dnf install nginx-module-<NAME>

Module availability can differ between repository channels and package builds. Check the selected channel before assuming a module exists, and test the module with the exact NGINX version you intend to run. A module compiled for a different package set can prevent NGINX from loading its configuration, so treat module installation as part of the same compatibility test as the core package.

Troubleshoot common installation and startup problems

DNF cannot find the repository or package

  • Check that /etc/yum.repos.d/nginx.repo exists and contains both stanzas without spelling errors.
  • Confirm that the stable stanza has enabled=1. If only the mainline stanza is enabled, verify that you intentionally selected it.
  • Check network and DNS access to the exact baseurl in the file.
  • Run sudo dnf update again after correcting the file so metadata is refreshed.

The signing-key fingerprint does not match

Decline the key import. Do not bypass GPG checking or replace the configured key URL with an unverified copy. Recheck the repository file, the connection to NGINX’s key endpoint, and the authoritative fingerprint in the NGINX installation guidance. A mismatch is a trust failure, not a prompt to choose a different answer.

sudo nginx returns an error

  • Read /var/log/nginx/error.log for the reported path, permission, or module problem.
  • Confirm that the configuration being read is /etc/nginx/nginx.conf, unless nginx -V shows a different compiled path.
  • If you recently installed a dynamic module, verify that its package belongs to the same repository channel and NGINX package set.

curl -I 127.0.0.1 cannot connect

  • Check the error log for startup failures.
  • Use the compiled-path command to find a non-default error log if /var/log/nginx/error.log has no relevant entry.
  • Run sudo nginx again after correcting the reported configuration or module issue, then repeat the local curl check.

The local response is not HTTP/1.1 200 OK

The request reached an HTTP service, but the returned status is not the documented default response. Review the active configuration and the access and error logs. If the package came from a different channel than intended, confirm repository enablement before making configuration changes.

Open Source NGINX versus NGINX Plus

The repository and commands in this guide install NGINX Open Source packages. NGINX Plus is a separately licensed product with its own repository and credentials. Only administrators who already have an NGINX Plus subscription should follow Plus-specific distribution instructions; adding the Open Source repository does not install or convert a server to NGINX Plus.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Installation checklist

  • CentOS 8 and sudo access confirmed.
  • /etc/yum.repos.d/nginx.repo created with stable enabled and mainline disabled unless deliberately selected.
  • Repository metadata refreshed with sudo dnf update.
  • Signing-key fingerprint compared with the official NGINX documentation before acceptance.
  • NGINX installed with sudo dnf install nginx.
  • Server started with sudo nginx.
  • curl -I 127.0.0.1 returns a response beginning with HTTP/1.1 200 OK.
  • Configuration and logs located at their expected paths, or verified with nginx -V when a package uses different paths.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.