If you’re looking to set up a web server on Fedora, Nginx is an excellent choice. Nginx is a high-performance web server that’s known for its scalability and flexibility. It’s also relatively easy to set up on Fedora, and in this blog, we’ll guide you through the steps.
Before we start, it’s important to note that there are two versions of Nginx available on Fedora: Nginx and Nginx Mainline. The Mainline version is the most recent release and contains the latest features and bug fixes. However, it’s not as stable as the regular Nginx version, so if you’re new to Nginx, we recommend sticking with the regular version.
Step 1: Install Nginx
To install Nginx on Fedora, open a terminal window and run the following command:
sudo dnf install nginx
This will download and install Nginx on your system.
Step 2: Start Nginx
After the installation is complete, you’ll need to start the Nginx service. To do this, run the following command:
sudo systemctl start nginx
Step 3: Enable Nginx
To ensure that Nginx starts automatically when your server boots up, you need to enable it. Run the following command:
sudo systemctl enable nginx
Step 4: Check Nginx status
You can check the status of Nginx by running the following command:
sudo systemctl status nginx
If Nginx is running, you’ll see a message that says “active (running)”.
Step 5: Configure Nginx
By default, Nginx will serve files from the /usr/share/nginx/html directory. If you want to serve files from a different directory, you’ll need to modify the Nginx configuration file. Open the configuration file using a text editor:
sudo nano /etc/nginx/nginx.conf
In the configuration file, look for the following line:
root /usr/share/nginx/html;
Replace “/usr/share/nginx/html” with the path to the directory you want to serve files from. Save the file and exit the text editor.
Step 6: Test Nginx
To test that Nginx is serving files correctly, create a simple HTML file in the directory you specified in the configuration file. For example, if you changed the root directory to /var/www/html, create a file called index.html in that directory:
sudo nano /var/www/html/index.html
Add some HTML to the file, such as:
<html>
<head>
<title>Welcome to my website</title>
</head>
<body>
<h1>Hello, world!</h1>
</body>
</html>
Save the file and exit the text editor. Then, open a web browser and go to the IP address or domain name of your server. You should see the contents of the index.html file you just created.
Congratulations! You’ve successfully set up a web server on Fedora using Nginx. From here, you can further configure Nginx to suit your needs, such as setting up virtual hosts or adding SSL certificates. Nginx has a wealth of features and documentation available, so be sure to explore and experiment with its capabilities.