How To Install Nginx on Fedora 43

Nginx has become one of the most popular web servers in the world, powering millions of websites with its exceptional performance and efficiency. If you’re running Fedora 43 and looking to set up a robust web server, Nginx is an excellent choice that offers lightweight resource consumption while handling high traffic loads with ease. This comprehensive guide will walk you through every step of installing and configuring Nginx on your Fedora 43 system, from initial setup to creating your first virtual host. Whether you’re a system administrator, developer, or enthusiast, you’ll learn how to get Nginx up and running quickly while understanding the fundamentals of its configuration.
What is Nginx?
Nginx (pronounced “engine-x”) is an open-source, high-performance web server that has revolutionized the way modern applications serve content. Originally created by Igor Sysoev in 2004, Nginx was designed to solve the C10K problem—handling 10,000 concurrent connections simultaneously.
Beyond serving static content, Nginx functions as a powerful reverse proxy server, load balancer, HTTP cache, and media streaming server. Its event-driven architecture allows it to handle thousands of concurrent connections with minimal memory overhead, making it significantly more efficient than traditional process-based web servers.
The advantages of using Nginx on Fedora 43 are numerous. It consumes less RAM compared to Apache, processes requests asynchronously, and excels at serving static files. Nginx is particularly valuable when you need to handle high concurrent connections, implement load balancing across multiple application servers, or set up a reverse proxy for Node.js, Python, or PHP applications. Many high-traffic websites including Netflix, Dropbox, and WordPress.com rely on Nginx to deliver content to millions of users daily.
Prerequisites
Before beginning the installation process, ensure your system meets these requirements:
- A fresh or existing Fedora 43 installation (server or workstation edition)
- Root privileges or a user account with sudo access
- An active internet connection for downloading packages
- Basic familiarity with Linux command-line interface
- At least 1GB of RAM (2GB recommended for production environments)
- Sufficient disk space (minimum 10GB available)
Optionally, having a registered domain name and understanding of DNS configuration will be helpful if you plan to host public-facing websites. However, you can complete this tutorial using just your server’s IP address for testing purposes.
Step 1: Update Your Fedora 43 System
Keeping your system current with the latest security patches and software updates is crucial before installing any new packages. Open your terminal and execute the following command:
sudo dnf update -y
This command instructs DNF (Dandified YUM), Fedora’s package manager, to update all installed packages to their latest versions. The -y flag automatically confirms the update without prompting for user input. Depending on how recently you’ve updated your system, this process might take several minutes.
Alternatively, you can use:
sudo dnf upgrade --refresh
This variation refreshes the package metadata before upgrading, ensuring you receive the most current package information from Fedora’s repositories. Wait for the process to complete, and reboot your system if kernel updates were installed.
Step 2: Install Nginx on Fedora 43
Fedora 43 includes Nginx in its default repositories, making installation straightforward. Execute this command to install the Nginx web server:
sudo dnf install nginx -y
The DNF package manager will resolve dependencies, download the necessary packages, and install Nginx along with any required libraries. You’ll see output displaying the download progress and installation status.
Once installation completes, verify that Nginx was installed successfully by checking the package information:
rpm -qi nginx
This displays detailed information about the installed Nginx package, including version, release date, size, and description.
To check the specific Nginx version installed on your system, run:
nginx -v
You should see output similar to nginx version: nginx/1.24.0 or newer. The version number confirms that the Nginx binary is accessible and ready for configuration.
Step 3: Start and Enable Nginx Service
Fedora 43 uses systemd as its service manager. To start the Nginx service immediately, execute:
sudo systemctl start nginx
This command initiates the Nginx process, but it won’t automatically start when your system reboots. To ensure Nginx starts automatically at boot time, enable the service:
sudo systemctl enable nginx
You can combine both operations into a single command:
sudo systemctl enable --now nginx
Verify that Nginx is running correctly by checking its status:
sudo systemctl status nginx
Look for “active (running)” in green text, which indicates the service is operational. The output also displays the main process ID (PID), memory usage, and recent log entries. If you see “inactive (dead)” or any errors, the service failed to start and requires troubleshooting.
Step 4: Configure Firewall for Nginx
Fedora 43 ships with Firewalld enabled by default, which blocks incoming connections to prevent unauthorized access. You must configure firewall rules to allow web traffic to reach your Nginx server.
First, confirm Firewalld is active:
sudo systemctl status firewalld
Add HTTP traffic (port 80) to the allowed services:
sudo firewall-cmd --permanent --add-service=http
For secure HTTPS connections (port 443), add the HTTPS service:
sudo firewall-cmd --permanent --add-service=https
The --permanent flag ensures these rules persist across system reboots. Reload the firewall to apply changes immediately:
sudo firewall-cmd --reload
Verify the rules were added successfully:
sudo firewall-cmd --list-services
You should see both “http” and “https” in the output alongside other default services like “dhcpv6-client” and “ssh”.
Step 5: Verify Nginx Installation
Now that Nginx is running and firewall rules are configured, verify the web server is listening for connections. Use the ss command to check listening sockets:
ss -antpl | grep :80
You should see output indicating Nginx is listening on port 80 (0.0.0.0:80 for IPv4 and :::80 for IPv6).
Determine your server’s IP address:
hostname -I
Or use:
ip a
Open a web browser and navigate to http://your-server-ip. You should see the default Nginx welcome page displaying “Welcome to nginx on Fedora!” with additional information about server configuration.
If the page doesn’t load, check these common issues:
- Verify Nginx service is running:
sudo systemctl status nginx - Confirm firewall rules are active:
sudo firewall-cmd --list-services - Check SELinux isn’t blocking connections:
sudo ausearch -m avc -ts recent - Ensure no other service is using port 80:
sudo lsof -i :80
Step 6: Understanding Nginx Configuration Files
Nginx’s configuration follows a hierarchical structure that’s both powerful and flexible. Understanding this structure is essential for effective server management.
The main configuration file resides at /etc/nginx/nginx.conf. This file contains global settings affecting the entire Nginx instance, including worker processes, error logging, and connection handling parameters.
Additional site-specific configurations are stored in /etc/nginx/conf.d/ directory. Any file ending with .conf in this directory is automatically included in the main configuration. This modular approach allows you to manage multiple websites without cluttering the main configuration file.
The default document root (where web files are served from) is /usr/share/nginx/html. This directory contains the default welcome page you saw earlier.
Nginx logs are stored in /var/log/nginx/:
access.log– Records all incoming requestserror.log– Contains error messages and diagnostic information
Before making any configuration changes, always test syntax validity:
sudo nginx -t
This command checks for syntax errors without actually applying changes. You’ll see “syntax is ok” and “test is successful” if everything is correct.
Always create backup copies before modifying configuration files:
sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.backup
Step 7: Configure Basic Nginx Settings
Open the main configuration file with your preferred text editor:
sudo nano /etc/nginx/nginx.conf
Or if you prefer vi:
sudo nano /etc/nginx/nginx.conf
Locate the server_name directive within the server block (typically around line 40). By default, it’s set to _ (underscore), which matches any hostname. Replace it with your actual domain name or server IP:
server_name example.com www.example.com;
If you’re using a domain name longer than 64 characters or multiple server names, add this directive in the http block:
server_names_hash_bucket_size 64;
The worker_processes directive defines how many worker processes Nginx should spawn. Setting this to auto lets Nginx automatically determine the optimal number based on available CPU cores:
worker_processes auto;
The worker_connections directive specifies the maximum number of simultaneous connections each worker can handle:
worker_connections 1024;
For high-traffic servers with adequate resources, you might increase this to 2048 or higher. Save your changes (Ctrl+O, Enter, Ctrl+X in nano).
Step 8: Create Custom Website Directory
Rather than using the default document root, create a dedicated directory for your website:
sudo mkdir -p /var/www/html/mysite
The -p flag creates parent directories if they don’t exist. Create a simple test page:
sudo nano /var/www/html/mysite/index.html
Add this HTML content:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Welcome to My Nginx Server</title>
</head>
<body>
<h1>Success! Nginx is working on Fedora 43</h1>
<p>This is a custom website served by Nginx.</p>
</body>
</html>
Save the file. Now set the correct ownership so Nginx can read the files:
sudo chown -R nginx:nginx /var/www/html/mysite
Set appropriate permissions:
sudo chmod -R 755 /var/www/html/mysite
The 755 permission allows the owner (nginx user) full access while giving read and execute permissions to others. This is crucial because improper permissions are a common cause of 403 Forbidden errors.
Step 9: Configure Nginx Virtual Host (Server Block)
Virtual hosts (called server blocks in Nginx terminology) allow you to host multiple websites on a single server. Create a new configuration file:
sudo nano /etc/nginx/conf.d/mysite.conf
Add this server block configuration:
server {
listen 80;
listen [::]:80;
server_name mysite.example.com;
root /var/www/html/mysite;
index index.html index.htm;
access_log /var/log/nginx/mysite_access.log;
error_log /var/log/nginx/mysite_error.log;
location / {
try_files $uri $uri/ =404;
}
location ~ /\.ht {
deny all;
}
}
Let’s break down this configuration:
listen 80;– Instructs Nginx to listen on port 80 for IPv4 connectionslisten [::]:80;– Enables IPv6 supportserver_name– Defines the domain or hostname for this server blockroot– Specifies the document root directoryindex– Lists files to serve as the directory indexaccess_loganderror_log– Define separate log files for this sitelocation /– Defines how to handle requests for the root locationtry_files– Attempts to serve the requested file, then directory, or returns 404location ~ /\.ht– Blocks access to .htaccess and similar files
Save the file. You can create multiple server blocks by creating additional .conf files in the same directory.
Step 10: Test and Reload Nginx Configuration
Always test your configuration before applying it:
sudo nginx -t
If you see “syntax is ok” and “test is successful”, proceed to reload Nginx:
sudo systemctl reload nginx
The reload command applies configuration changes without dropping existing connections, making it ideal for production environments. Use restart only when necessary:
sudo systemctl restart nginx
Verify the reload succeeded:
sudo systemctl status nginx
Check the error log if issues occur:
sudo tail -f /var/log/nginx/error.log
Step 11: Access Your Website
Open your web browser and navigate to your configured server name or IP address:
http://mysite.example.com
Or:
http://your-server-ip
You should see your custom HTML page. Test from the command line using curl:
curl http://localhost
This displays the HTML source code of your index page. Test from external networks to ensure your firewall rules are working correctly.
Basic Nginx Management Commands
Master these essential commands for day-to-day Nginx administration:
Service Control:
- Start Nginx:
sudo systemctl start nginx - Stop Nginx:
sudo systemctl stop nginx - Restart Nginx:
sudo systemctl restart nginx - Reload configuration:
sudo systemctl reload nginx - Check status:
sudo systemctl status nginx - Enable auto-start:
sudo systemctl enable nginx - Disable auto-start:
sudo systemctl disable nginx
Log Monitoring:
- View error logs in real-time:
sudo tail -f /var/log/nginx/error.log - View access logs:
sudo tail -f /var/log/nginx/access.log - Check last 100 lines:
sudo tail -n 100 /var/log/nginx/error.log
Configuration Testing:
- Test syntax:
sudo nginx -t - Test and display config:
sudo nginx -T
Troubleshooting Common Issues
Nginx Fails to Start
Check if another process is using port 80:
sudo lsof -i :80
If Apache or another web server is running, stop it or configure Nginx to use a different port.
SELinux Permission Denied Errors
Fedora 43 has SELinux enabled by default. Check SELinux status:
getenforce
If SELinux is blocking Nginx, check audit logs:
sudo ausearch -m avc -ts recent | grep nginx
Allow Nginx to make network connections:
sudo setsebool -P httpd_can_network_connect on
Set correct SELinux context for custom document roots:
sudo semanage fcontext -a -t httpd_sys_content_t "/var/www/html/mysite(/.*)?"
sudo restorecon -Rv /var/www/html/mysite
Configuration Syntax Errors
Always run sudo nginx -t before reloading. Common errors include:
- Missing semicolons at the end of directives
- Mismatched curly braces
- Invalid directive names
- Incorrect file paths
403 Forbidden Errors
This typically indicates permission problems:
- Verify file ownership:
ls -la /var/www/html/mysite - Check directory permissions:
sudo chmod 755 /var/www/html/mysite - Ensure Nginx can read parent directories
- Review SELinux contexts
502 Bad Gateway Errors
This occurs when Nginx cannot reach upstream servers (PHP-FPM, Node.js apps, etc.). Verify:
- Backend service is running
- Socket or port configuration matches
- Firewall allows localhost communication
- SELinux boolean:
sudo setsebool -P httpd_can_network_connect on
Security Best Practices
Securing your Nginx installation protects your server and data from potential threats.
Keep Nginx Updated
Regularly update Nginx to receive security patches:
sudo dnf update nginx
Hide Nginx Version
Prevent version disclosure by adding to the http block in nginx.conf:
server_tokens off;
Implement SSL/TLS Certificates
Always use HTTPS in production. Install Let’s Encrypt certificates using Certbot for free SSL/TLS encryption. This encrypts data between clients and your server, protecting sensitive information.
Set Proper File Permissions
Never use 777 permissions. Web files should be owned by the Nginx user with 644 for files and 755 for directories.
Configure Security Headers
Add these headers to protect against common attacks:
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
Implement Rate Limiting
Protect against DDoS attacks by limiting request rates:
limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;
Monitor Logs Regularly
Set up automated log monitoring and use fail2ban to automatically ban suspicious IP addresses attempting brute-force attacks.
Congratulations! You have successfully installed Nginx. Thanks for using this tutorial for installing the Nginx web server on Fedora 43 Linux system. For additional help or useful information, we recommend you check the official Nginx website.