FedoraRHEL Based

How To Install Nginx on Fedora 39

Install Nginx on Fedora 39

In this tutorial, we will show you how to install Nginx on Fedora 39. Nginx stands as a robust web server, excelling in performance and scalability. Fedora 39, a cutting-edge Linux distribution, offers an ideal platform for deploying Nginx and managing web services.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the Nginx web server on a Fedora 39.

Prerequisites

Before diving into the installation process, let’s ensure that you have everything you need:

  • A server running one of the following operating systems: Fedora 39.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • You’ll need an active internet connection to download Nginx [engine x] and its dependencies.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Nginx on Fedora 39

Step 1. Begin by confirming that your Fedora 39 system is properly installed. If not, make sure to complete the installation before proceeding. Once your system is in order, it’s time to update it:

sudo dnf clean all
sudo dnf update

Step 2. Installing Nginx on Fedora 39.

Now that your Fedora 39 system is updated and you’re familiar with basic terminal operations, it’s time to install Nginx:

sudo dnf install nginx

This command will fetch and install Nginx on your Fedora system. Once the installation is complete, you’re ready to take the next step.

Nginx installation is complete, but it’s essential to start the service and configure it to start automatically on system boot. Use the following commands:

sudo systemctl start nginx
sudo systemctl enable nginx
sudo systemctl status nginx

The first command initiates the Nginx service, while the second ensures that it starts with the system. The third command provides the status of Nginx, allowing you to verify that it’s running correctly.

Step 3. Configuring Virtual Hosts.

Nginx is now up and running, but it’s a good practice to configure virtual hosts to host multiple websites on a single server.

Server blocks, often referred to as virtual hosts, are configurations that allow Nginx to serve multiple websites on a single server. They are defined in separate configuration files within the /etc/nginx/conf.d/ directory.

Start by creating a new configuration file for your virtual host. Replace yourwebsite.com with your actual domain name:

sudo nano /etc/nginx/conf.d/yourwebsite.com.conf

Inside the configuration file, you can set up your virtual host as follows:

server {
    listen 80;
    server_name yourwebsite.com www.yourwebsite.com;
    root /var/www/yourwebsite.com/public_html;
    access_log /var/log/nginx/yourwebsite.com.access.log;
    error_log /var/log/nginx/yourwebsite.com.error.log;

    location / {
        try_files $uri $uri/ =404;
    }
}

In this example:

  • listen 80: Specifies that this virtual host listens on port 80, the default HTTP port.
  • server_name: Defines the domain names for your website.
  • root: Points to the root directory of your website’s files.
  • access_log and error_log: Specify the log file locations.
  • The location block handles requests to your site.

Before you apply your new configuration, it’s a good practice to test it for any errors:

sudo nginx -t

If the test returns “successful,” you can proceed to apply the new configuration:

sudo systemctl reload nginx

Step 4. Firewall Setup.

While your Nginx server is ready to host websites, it’s crucial to configure your firewall to allow web traffic. To allow HTTP and HTTPS traffic through your firewall, execute these commands:

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

Finally, reload the firewall to apply the changes:

sudo firewall-cmd --reload

To verify your settings:

sudo firewall-cmd --list-services

Congratulations! You have successfully installed Nginx. Thanks for using this tutorial for installing the Nginx [engine x] web server on your Fedora 39 system. For additional Apache or useful information, we recommend you check the official Nginx website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button