How to install Nginx on Fedora?

Image of NGINX, a web server.

Nginx is an open-source web server (free HTTP Server software), in addition to its HTTP Server capabilities, it can also function as a Proxy Server for email (IMAP, POP3, and SMTP) and a Reverse Proxy and Load Balancer for HTTP, TCP, and UDP Servers. As of today, Nginx has been used by far more than 400 million top websites and numbers are increasing every day due to its simplicity compared to legacy web servers.

Image of NGINX, a web server.

In this article, I’ll explain the steps to install Nginx on Fedora.

0. Prerequisites to install Nginx on Fedora.

You’ll need a computer or server that has the latest copy of Fedora Linux installed (clean install with no default webserver) and a root (or root equivalent) user account to install the software.

1. Updating the Fedora Linux.

Before we hit installation of Nginx directly it is necessary that we update the system and make sure everything is up to date. This will help us install everything new without any glitches.

sudo dnf upgrade --refresh

For the very first time, it may take time; some serious time.

2. Installing Nginx.

Nginx comes with two different versions as stable and mainline. Stable Nginx has everything stable, while Mainline Nginx is the latest and may have some bugs but that too gets fixed fast with every new update.

Nginx itself recommends using the mainline version unless you are not going to update the system often.

If you wish to install Stable Nginx, skip the Mainline instructions and go directly to installation.

Switching the installation to Mainline.

Use the below command to enable the mainline repository.

sudo dnf module enable nginx:mainline

Install Nginx.

sudo dnf install nginx

Start and enable the Nginx.

In RHEL-based systems, you have to start and enable the application once they are installed successfully.

sudo systemctl start nginx

Enable will make the application start when you reboot or restart the system.

sudo systemctl enable nginx

3. Configure firewall rules.

Fedora and RHEL based Linux is secured with a firewall by default. You need to allow HTTP (Port 80) and HTTPS (Port 443) in order to make the Nginx accessible outside the machine or web server.

HTTP (Port 80).

sudo firewall-cmd --permanent --zone=public --add-service=http

HTTPS (Port 443).

sudo firewall-cmd --permanent --zone=public --add-service=https

Reload firewall to make changes into effect.

sudo firewall-cmd --reload

Now Nginx is ready to get started with a website. A default index page is there that will show a dummy page to verify whether Nginx is working or not. Just open the IP address or Domain name if mapped already in the browser.

4. Configure Nginx for web.

The default configuration file is located at /etc/nginx/nginx.conf and you can put all the configurations there.

If you want to manage multiple websites on the same server then you can put individual per-site configurations on /etc/nginx/sites-available/ and /etc/nginx/sites-enabled/ directory.

Both the directories are similar where actual files are in the ‘sites-available’ directory and symbolic links to those files are made on the ‘sites-enabled’ directory.

You need to restart (hard restart) or reload (soft restart) the Nginx in order to make the changes come into action. Prefer to reload if you are dealing with live traffic, it will take a very small time but worth it.

Do test your configurations before you apply them using command nginx -t. It will show any possible errors before you apply it after the restart or reload.

sudo systemctl restart nginx

or

sudo systemctl reload nginx

New to Nginx? Is this your first install? Understand what default configuration means.

Read: atulhost.com/default-nginx-configuration

Read the following to further optimize the Nginx.

Read: atulhost.com/optimizing-nginx-for-high-traffic-websites

By Atul Kumar Pandey

Hi, I'm creator of atulhost, comes from business management and tech background. I love to do research on modern business insights and latest technological solutions.

Leave a comment

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