NGINX is an open-source, high-performance HTTP server software. In the tutorial, you will learn how to install the Nginx web server on Fedora Linux systems.

Advertisement

Prerequisites

  • A running Fedora Linux system
  • A user account with sudo or root access.

Step 1: Update Operating System

The first step is to update all the existing packages on your Fedora operating system. This tutorial is using the sudo command. To set up an existing or new sudo account, visit our tutorial on Adding a User to Sudoers on Fedora.

Let’s update all packages by executing:

sudo dnf upgrade --refresh -y 

Step 2: Install Nginx Server on Fedora

To install Nginx is very easy on Fedora distributions given the six-monthly releases, and its constant updating of packages during its time means Nginx is, for the most part, always up to date.

  1. Given that Fedora is used to having the most updated packages, first enable the mainline repository, which Nginx recommends using.
    sudo dnf module enable nginx:mainline 
    

    Type Y, then press the ENTER KEY to proceed with the installation.

  2. Next, open your terminal, and execute the following command to begin the installation process.
    sudo dnf install nginx

    Type Y, then press the ENTER KEY to proceed with the installation.

  3. Once installed, confirm the installation by checking the Nginx build version.
    nginx -v
    Output
    nginx version: nginx/1.23.3
  4. By default, the Nginx service is not enabled or active once installed. To enable Nginx, use the following command.
    sudo systemctl enable nginx --now
  5. Now check the service status to confirm Nginx is running without any errors.
    systemctl status nginx

    As above, the status should be active (running). At this point, you have installed the Nginx application.

    Step 3: Adjust Firewall Rules

    By default, Fedora systems uses firewalld to secure the system. You need to update firewall rules to allow the port 80 (HTTP) and 443 (HTTPS). This can be done by running the following commands:

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

    Reload firewall to make changes into effect.

    sudo firewall-cmd --reload

    Once you have your server’s IP address, open up your favourite Internet Browser, and check the default landing page is working.

    Step 4: Create Nginx Server Block

    By default, the Nginx server block, similar to Apache virtual hosts, is dealt with in the /etc/nginx/conf.d directory. However, the Nginx installation varies from different versions and distributions utilizing either the conf.d or sites-available/sites-enabled by default. For the tutorial, the site’s directories will be used to keep a standard.

    Next, create your server block configuration file. The name your_domain.conf will be used for the tutorial, but this can be named anything you prefer.

    sudo nano /etc/nginx/conf.d/your_domain.conf

    You can paste the following example code into the block. This is just an HTTP-only example for basic testing.

    
    server {
    
     listen 80;
    
     server_name your_domain www.your_domain;
     root /var/www/your_domain/html;
    
      index index.html index.htm;
    
     location / {
      try_files $uri $uri/ =404;
     }
    }
    
    

    The example shows your server is listening for two server names, “your_domain” on port 80.

    You will need to change the root directory to the name/location of the root directory you create.

    Step 5: Final Configuration & Test run

    The server name’s hash bucket size is changed as sometimes problems arise from adding additional servers.

    Next, test your Nginx to make sure it’s working before properly restarting.

    sudo nginx -t

    The output should be if no errors in the syntax:

    Output
    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful

    If you have the following ok output, restart the Nginx server for the changes to take place.

    sudo systemctl restart nginx

    Now open your Internet Browser and type in the server domain name. You should see your server block is live.

    How to Update Nginx

    Nginx will be updated by default when a new version hits the repositories. Before upgrading, it’s always advised to back up your Nginx directory or, at the very least, the nginx.conf file. You can do either with the following command.

    Back up nginx.conf (Highly Recommended):

    sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx-backup.conf

    Back up your entire Nginx folder if you prefer:

    sudo cp /etc/nginx/ /etc/nginx-bkup

    Next, run the standard update command.

    sudo dnf upgrade --refresh

    If an upgrade is available, run the upgrade.

    You may be prompted this during an upgrade or installation, but manually doing this beforehand is pretty essential. For large Nginx configurations of multiple sites, backing up to something like Github or Gitlab would be even more beneficial.

    How to Remove (Uninstall) Nginx

    To remove Nginx if you no longer use it, this can be done using the following command:

    sudo dnf autoremove nginx

    This command will also remove any unused dependencies that came with the installation.

    To reset the nginx module from mainline back to default, use the following command.

    sudo dnf modules reset nginx

    Conclusion

    In the tutorial, you have learned to install and set up basic Nginx configuration on your domain on Fedora Workstation or Server, along with creating a free SSL certificate using Let’s Encrypt. Overall, Nginx is the most used and popular web application software now, with every month and year surpassing taking more market share from Apache.

    Some new contenders are starting to pop up, such as Openlitespeed but given these other web applications, for now, focus on specific things like WordPress. Nginx will be the go-to web application for some time.

    Share.
    Leave A Reply