Skip to main content

How to Install Nginx on Fedora

Nginx is a popular web server that is known for its high performance and scalability. It is often used as a reverse proxy, load balancer, and HTTP cache. In this tutorial, we will walk you through the process of installing Nginx on a Fedora machine.

Prerequisites

Before we begin, make sure that you have a Fedora machine with sudo privileges. You can check if your system has sudo access by running the following command:

sudo ls /root

If you see a list of files and directories, you have sudo access. If not, you will need to ask your system administrator for access.

Step 1: Update the System

Before installing Nginx, it is recommended to update your system to ensure that you have the latest packages and security patches installed. Run the following command to update your system:

sudo dnf update

This will update all the packages on your system to their latest version.

Step 2: Install Nginx

To install Nginx, you can use the dnf package manager. Run the following command to install Nginx:

sudo dnf install nginx

This will download and install Nginx and all its dependencies.

Step 3: Start Nginx

After installing Nginx, you can start the service using the systemctl command:

sudo systemctl start nginx

You can check the status of Nginx by running the following command:

sudo systemctl status nginx

This will show you if Nginx is running or not. If it is not running, you can start it using the command above.

Step 4: Configure Nginx

By default, Nginx listens on port 80. You can test if Nginx is running by visiting your server's IP address in a web browser. If you see the default Nginx welcome page, it means that Nginx is running as expected.

To customize the Nginx configuration, you can edit the configuration file located at /etc/nginx/nginx.conf. You can use any text editor to edit this file. Here is an example of how you can edit the file:

sudo nano /etc/nginx/nginx.conf

This will open the file in the nano text editor. You can make any changes to the file and then save and exit.

Step 5: Test Nginx

To test if Nginx is working as expected, you can create a simple HTML file and serve it using Nginx. Here is an example of how you can create a simple HTML file:

sudo nano /usr/share/nginx/html/index.html

This will create a new file called index.html in the /usr/share/nginx/html directory. You can add some HTML code to this file, such as:

<html>
<head>
<title>Hello World</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>

Save and exit the file. Then, restart Nginx using the following command:

sudo systemctl restart nginx

You can now visit your server's IP address in a web browser, and you should see the "Hello World" message that you just created.

Conclusion

In this tutorial, we walked you through the process of installing Nginx on a Fedora machine. We also showed you how to start, configure, and test Nginx. Nginx is a powerful web server that can be used for a variety of purposes, and we hope that this tutorial has helped you get started with it.