keepcalculator

06 Numbers and Powers

Install Nginx on CentOS 8 from Stable or Mainline

Card No. 06·29309 · Updated · Standard formula, shown below

Install Nginx on CentOS 8 by adding the official Nginx repository, choosing either its stable or mainline package stream, and enabling the service. You will need administrator access and a CentOS 8 system; note that CentOS Linux 8 reached end of life in 2021, so its package sources may no longer work reliably.

What You’ll Need

  • A CentOS 8 server or virtual machine with a working network connection.
  • A user account with sudo privileges, or access to the root account.
  • A package repository source that your system can reach. Because CentOS Linux 8 is end of life, its standard mirrors may have been retired. For an internet-facing or long-term server, consider a supported operating-system release instead.
  • Optional: an open firewall rule for HTTP (port 80) or HTTPS (port 443) if clients outside the machine must connect.

Step-by-Step

  1. Check the operating system and privileges. Run cat /etc/centos-release to confirm the release, then check that your account can use sudo. If you are already root, omit sudo from the commands below. Do not confuse CentOS Linux 8 with CentOS Stream 8; repository instructions and availability can differ.
  2. Check whether package management can reach its repositories. Run sudo dnf makecache. If it succeeds, proceed. If it reports that mirrors or repository metadata are unavailable, this is likely due to CentOS Linux 8’s end-of-life status, not an Nginx configuration problem. Use a supported operating system or an appropriate, trusted archive configuration for your environment; do not blindly replace repository files with an unverified source.
  3. Add the Nginx repository configuration. Download the repository file supplied by Nginx using HTTPS:
    sudo curl -fsSLo /etc/yum.repos.d/nginx.repo https://nginx.org/packages/centos/8/x86_64/RPMS/nginx.repo
    This URL is for CentOS 8 on x86_64. Confirm your architecture with uname -m. If you run another architecture or a CentOS Stream variant, use repository instructions applicable to that system rather than assuming this file matches it.
  4. Choose stable or mainline before installing. Open the file with sudo vi /etc/yum.repos.d/nginx.repo or another text editor. The file contains repository sections for the available Nginx streams. In the section for the stream you want, set enabled=1; set enabled=0 for the other stream. Choose stable for a conservative release stream, or mainline for the newer feature and development stream. Keep only one of those streams enabled to avoid ambiguous package selection. Save and close the file.
  5. Refresh metadata and confirm the selected package source. Run sudo dnf clean metadata, followed by sudo dnf makecache. Then inspect available package information with sudo dnf info nginx. Check the repository shown and the version offered. If the command still sees an unexpected stream, review the enabled settings and any other repository files that provide Nginx.
  6. Install Nginx. Run sudo dnf install nginx and review the transaction summary before confirming. If DNF reports dependency conflicts, read which packages it proposes to replace or downgrade; do not approve a change you do not understand. A pre-existing Nginx package from another repository may need a planned migration.
  7. Enable and start the service. Run sudo systemctl enable --now nginx. This starts Nginx now and configures it to start automatically on boot. Check the result with systemctl status nginx. Press q to leave the status display.
  8. Check the configuration and local response. Run sudo nginx -t; the output should say the configuration test is successful. Then run curl -I http://localhost/. A response such as HTTP/1.1 200 OK confirms that a local HTTP request reached the server. The default document and response can vary if you already had custom configuration.
  9. Allow web traffic if needed. If the system uses firewalld and external HTTP access is required, run sudo firewall-cmd --permanent --add-service=http and sudo firewall-cmd --reload. For HTTPS, add the https service as well. Also check any cloud firewall, router, or network security rules; opening firewalld alone does not change those controls.

Common Mistakes

Enabling both streams: Stable and mainline are alternative package streams. Leaving both enabled can make package selection unclear. Disable the unused stream before installing or updating.

Assuming CentOS 8 repositories still operate normally: CentOS Linux 8 is end of life, and normal mirror locations may be unavailable. Fixing mirror configuration will not restore ongoing operating-system security support. For a production server, plan a move to a supported platform.

Using a repository for the wrong architecture: The example repository file targets x86_64. Check uname -m and follow the matching repository instructions.

Expecting remote access to work just because Nginx runs: The service can be healthy locally while firewalld, a cloud firewall, or another network control blocks outside traffic. Test each layer separately.

Tips

  • Save a copy of any existing Nginx configuration before changing packages or repository sources.
  • Use sudo nginx -t before applying configuration edits. If the test passes, reload without stopping active connections using sudo systemctl reload nginx.
  • Check the selected stream after repository changes with dnf info nginx, and review the proposed version before updates.
  • Keep the operating system and Nginx packages maintained. Installing a newer Nginx stream does not make an end-of-life operating system supported.

Troubleshooting

DNF cannot find the repository or download metadata: Verify network access, DNS, and the repository file’s URL. If standard CentOS 8 mirrors are retired, use a properly maintained system or a trusted archive appropriate to the machine. Avoid disabling TLS checks to get around certificate or connection errors.

The Nginx repository does not appear: Check that /etc/yum.repos.d/nginx.repo exists and contains the expected repository sections. Run sudo dnf clean all and sudo dnf makecache, then inspect sudo dnf repolist. A wrong architecture or malformed repository file can prevent it from appearing.

Installation fails with a conflict: Review installed packages with rpm -q nginx and the DNF error details. A package from a different source may conflict. Back up configuration and plan a package-source transition; do not remove packages or accept downgrades without understanding the impact.

The service will not start: Run sudo nginx -t and sudo journalctl -u nginx -b --no-pager. Correct the reported syntax error, port conflict, or file-permission issue, then try sudo systemctl restart nginx.

Local requests work but remote requests time out: Confirm Nginx is listening with sudo ss -ltnp, open the appropriate firewalld service, and check external firewall rules and routing. A refused connection and a timeout can point to different network issues.

Frequently Asked Questions

Should I choose stable or mainline?
Choose stable when you prefer the stable release stream. Choose mainline when you specifically need its newer features and accept that it changes more frequently. Keep only the chosen stream enabled.

Can I install Nginx with CentOS’s default repositories instead?
Possibly, if a suitable package is available from your configured repositories. The Nginx repository is useful when you want to select its stable or mainline stream. Check the package source and version before installing.

Does this work on CentOS Stream 8?
Do not assume the CentOS Linux 8 repository file applies to CentOS Stream 8. Check the current Nginx repository instructions for your exact release and architecture, and consider that Stream 8 is also end of life.

How can I tell which Nginx version is installed?
Run nginx -v to show the version. Use dnf info nginx to inspect package details and its repository source.

Why can I reach Nginx locally but not from another computer?
The service may be running while firewalld, a cloud firewall, network routing, or an upstream security rule blocks the connection. Check each layer and verify that the server listens on the expected address and port.

Is installing Nginx enough to enable HTTPS?
No. HTTPS also requires a TLS certificate and a suitable server configuration, plus access to port 443 through relevant firewalls. Test configuration changes with nginx -t before reloading.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →