Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk10 min

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

Install NGINX on CentOS 8 from the official repository. This guide covers stable versus mainline channels, GPG key verification, DNF commands, configuration paths, modules and startup troubleshooting.

Free tools Windows power users keep installed

One-click scans. No signup required.

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

Install the open-source NGINX package on CentOS 8 by adding NGINX’s official yum repository, refreshing metadata, importing and checking the repository signing key, and installing with dnf. The stable channel is enabled by default; the mainline channel is available but opt-in. After installation, start the server with sudo nginx and verify it locally with curl -I 127.0.0.1.

This procedure follows NGINX’s repository method for RHEL-based systems, a method the vendor recommends for production environments. You need a CentOS 8 host with sudo access and outbound access to the repository.

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.

What you will install

The procedure installs NGINX Open Source from the official NGINX package repository rather than from an arbitrary third-party build. CentOS is treated as a RHEL-based operating system in NGINX’s installation guidance, so the repository format uses yum/dnf conventions and the CentOS release and architecture variables.

The repository definition contains two channels:

  • Stable: enabled by default and intended for a more conservative production update path.
  • Mainline: disabled by default and enabled only when you deliberately choose the newer development line.

Both channels use GPG signature checking. Your package manager may ask to import the NGINX signing key during the first installation or repository refresh. Do not accept a key until its complete fingerprint matches the fingerprint published in the current NGINX installation guide.

Check prerequisites before changing the system

Confirm the operating system

Run the following command and make sure the machine is the CentOS 8 system you intend to modify:

cat /etc/centos-release

The repository URL uses $releasever, so a host reporting a different major release will resolve to a different repository path. Do not copy a CentOS 8 repository file onto another major release without adapting and validating it.

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

Confirm administrative access

Most installation commands need root privileges. Check that your account can use sudo:

sudo -v

If sudo is not configured, have an administrator perform the steps or grant the minimum required administrative access. You also need network connectivity to nginx.org; a firewall, proxy, or DNS policy that blocks the repository will prevent metadata downloads.

Decide which release channel you need

Use stable unless you have a specific reason to test or deploy mainline packages. Consider your application’s compatibility, the modules you require, and how quickly you want new NGINX changes. The repository file can define both channels while keeping mainline disabled, allowing an intentional switch later.

Create the official NGINX repository file

Create /etc/yum.repos.d/nginx.repo as root. The following is the repository layout published by NGINX:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo tee /etc/yum.repos.d/nginx.repo >/dev/null <<'EOF'
[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
EOF

The single quotes around EOF are intentional: they stop the shell from expanding $releasever and $basearch while the file is being created. DNF substitutes those variables when it reads the repository definition.

Review the file before proceeding:

sudo sed -n '1,120p' /etc/yum.repos.d/nginx.repo

Check that nginx-stable has enabled=1, nginx-mainline has enabled=0, GPG checking is enabled in both sections, and both sections reference the NGINX signing-key URL. Keeping mainline disabled avoids an accidental channel change during a routine update.

Refresh metadata and install NGINX

Update repository metadata

Refresh package metadata before installing. On CentOS 8, dnf is the normal successor to yum:

sudo dnf update

This command downloads current metadata and may update installed packages. Read the transaction summary and approve it only if the proposed updates are acceptable for the machine. If you want to refresh metadata without applying unrelated package updates, use your organization’s normal DNF metadata workflow, then continue with the install command.

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

Install the package from stable

sudo dnf install nginx

DNF should show the package source and the signing-key prompt when the key is not already trusted. The equivalent command documented on the official package page is sudo yum install nginx; on CentOS 8, the DNF form is the usual choice and uses the same repository configuration.

Choose mainline deliberately, if required

If you have tested mainline and intentionally need it, enable that repository before installing or updating:

sudo dnf config-manager --enable nginx-mainline

After enabling it, inspect the transaction that DNF proposes. Stable remains the default in the published configuration, but enabling mainline changes which repository can provide NGINX packages. If you later decide to return to stable, disable mainline and enable stable explicitly:

sudo dnf config-manager --disable nginx-mainline
sudo dnf config-manager --enable nginx-stable

Test the resulting package selection in a staging system before changing a production host. The official guidance does not promise identical module or application compatibility for every deployment.

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

Verify the NGINX signing key safely

GPG verification protects you from installing a package whose signature does not match the repository’s trusted key. The repository has gpgcheck=1 and points to https://nginx.org/keys/nginx_signing.key.

  1. When DNF asks whether to import a key, pause at the prompt rather than accepting automatically.
  2. Record the complete fingerprint displayed by the package manager. Do not rely on a shortened key ID.
  3. Compare every fingerprint character with the fingerprints published in NGINX’s current installation guide, using an independently obtained copy of that guide if your environment requires out-of-band verification.
  4. Accept the key only when the fingerprint matches exactly. If it differs, answer no, stop the installation, and investigate DNS, proxy interception, repository configuration, or a possible man-in-the-middle condition.

A successful key check does not replace ordinary change control. Keep the repository URL, the date of the verification, and the selected channel in your system records so another administrator can reproduce the decision.

Start NGINX and verify that it serves HTTP

Start the server with:

sudo nginx

Then make a request to the loopback address:

curl -I 127.0.0.1

A working default server should return headers beginning with HTTP/1.1 200 OK. The -I option requests headers only, so this is a quick local check that NGINX accepted its configuration, bound to the HTTP listener, and returned a response.

If you need to stop the process while troubleshooting, use the NGINX control command appropriate to your package and configuration rather than killing an arbitrary process. Before any reload or restart, validate the configuration syntax:

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

A successful test reports that the syntax is okay and the test is successful. Treat any error as a deployment blocker: fix the named file and line, run the test again, and only then reload or restart.

Know the important files and paths

Main configuration

The default main configuration file is:

/etc/nginx/nginx.conf

Read it before making changes so you understand which server blocks and include directives are active. Keep a backup of the original file and make one logical change at a time. After editing, run sudo nginx -t and keep the command output with your change record.

Access and error logs

NGINX writes logs under:

/var/log/nginx/

The standard files are:

  • /var/log/nginx/access.log for requests that reach NGINX.
  • /var/log/nginx/error.log for startup, configuration, connection, and upstream errors.

When a request fails, inspect the error log at the same time as you repeat the request. Correlating the timestamp and request path is more reliable than guessing from the browser’s error page.

Discover compiled paths when a package differs

Packages can be built with different compile-time defaults. Inspect the configure arguments with:

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.
nginx -V 2>&1 | awk -F: '/configure arguments/ {print $2}' | xargs -n1

Use the resulting paths to locate the active configuration, module directory, PID file, and log locations when they do not match the defaults above. This is especially useful after replacing a distribution package, installing a custom build, or troubleshooting a host that has more than one NGINX installation.

Stable versus mainline: which repository should you enable?

Decision factor Stable channel Mainline channel
Repository state in the published file Enabled by default (enabled=1) Disabled by default (enabled=0)
Release posture More conservative choice for routine production operations Newer line that you opt into deliberately
How to select it Leave nginx-stable enabled Run sudo dnf config-manager --enable nginx-mainline
Compatibility expectation Still test your application and modules before rollout Test especially carefully with your application and module set
Rollback planning Keep package and configuration backups Plan a tested path back to stable before enabling it

“Stable” does not mean that every application or third-party module will behave identically across updates, and “mainline” is not a guarantee of a feature your application needs. Choose based on the versions your application supports, the modules you depend on, your maintenance window, and your ability to test. Keep all hosts in a service tier on the same channel unless you have a documented reason to mix them.

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 deployment needs a module supplied as a separate NGINX package, install it by name:

sudo dnf install nginx-module-<NAME>

Replace <NAME> with the module name available in the selected repository. Do not assume that a module built for one NGINX release line is compatible with another. After installing a module, check the active configuration for its load directive, run sudo nginx -t, and perform the same local HTTP check. If the module is not found, confirm that you selected the repository channel that publishes it and inspect the package’s compiled module paths with nginx -V.

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

Troubleshoot common installation and startup failures

DNF cannot find the nginx package

  • Display the repository file and verify the section name, URL, and enabled value.
  • Run sudo dnf update again to refresh metadata.
  • Check that $releasever and $basearch resolve to a repository path that exists for the host.
  • Check DNS, proxy, and firewall access to nginx.org.

Do not work around a missing package by downloading an unrelated RPM from an unverified source. Correct the repository or network problem first.

The key fingerprint does not match

Decline the import. Recheck that you are using the official key URL, compare the full fingerprint with the current NGINX documentation, and investigate any TLS-inspecting proxy or DNS anomaly. A mismatch is a trust failure, not an invitation to proceed with --nogpgcheck.

Port 80 is already in use

If sudo nginx fails because it cannot bind the HTTP port, identify the service already listening on that port and decide which service should own it. Do not blindly stop a production service. If NGINX should use another listener, change the relevant listen directive in the active server configuration, validate with sudo nginx -t, and repeat the local check against the chosen port.

The configuration test fails

Read the exact filename and line number in the error. Typical causes include a missing semicolon, a typo in a directive, an include file that does not exist, or a module directive without the corresponding module package. Correct one issue at a time, rerun sudo nginx -t, and do not reload until it reports success.

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

curl -I 127.0.0.1 returns connection refused

  • Run sudo nginx -t to rule out a configuration problem.
  • Run sudo nginx and watch for an error message.
  • Inspect /var/log/nginx/error.log for bind, permission, or include errors.
  • Use the paths reported by nginx -V if the log is not under /var/log/nginx/.

If NGINX starts but a remote client cannot connect, separate the local application check from network policy: first make the loopback request succeed, then examine the host firewall, cloud security rules, load balancer, and DNS.

The response is not HTTP 200

A non-200 status can be valid for a custom configuration, but it may indicate that your server block is not the one you expected. Inspect /etc/nginx/nginx.conf and its included files, confirm the request’s host and port, and correlate the request with access.log and error.log. The documented default verification result is a response beginning with HTTP/1.1 200 OK; deviations should be explained by an intentional configuration.

After the first successful response

  1. Save a copy of /etc/nginx/nginx.conf and record the repository channel you selected.
  2. Review the access and error log locations and make sure your log collection or rotation policy covers them.
  3. Define your server blocks and content or reverse-proxy targets in a controlled change, rather than editing several unrelated settings at once.
  4. Run sudo nginx -t for every configuration change.
  5. Use a local curl -I 127.0.0.1 check after starting or reloading, then test the real hostname and application path from an appropriate client.
  6. Keep stable and mainline decisions consistent across a service tier, and test module updates before production deployment.

When NGINX Plus is relevant

NGINX Plus is a separately licensed product with its own repository and credentials. The repository file and commands in this guide install NGINX Open Source; they do not install NGINX Plus. Use the Plus procedure only when your organization has an NGINX Plus subscription and the required repository credentials.

CentOS 8 installation checklist

  • CentOS 8 is confirmed and the account has sudo privileges.
  • /etc/yum.repos.d/nginx.repo contains the official stable and optional mainline sections.
  • Stable is enabled unless mainline was an explicit, tested choice.
  • sudo dnf update completed and sudo dnf install nginx selected the intended repository.
  • The GPG fingerprint was compared in full with NGINX’s published fingerprint before key acceptance.
  • sudo nginx starts the server.
  • curl -I 127.0.0.1 returns the expected local response, normally beginning with HTTP/1.1 200 OK.
  • Configuration, logs, module paths, and any deviations from defaults are documented.

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.

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

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 from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair 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.