Tutorial: Installing Nginx on Fedora Server 40 and Supporting Multiple Sites

Tutorial: Installing Nginx on Fedora Server 40 and Supporting Multiple Sites

Fedora 40 is a cutting-edge Linux distribution renowned for its stability, robust features, and innovative approach to open-source technology. As a community-driven project sponsored by RedHat, Fedora consistently pushes the boundaries of what's possible in server environments.

Its commitment to incorporating the latest open-source technologies provides a solid foundation for a wide array of server applications, making it an excellent choice for both novice and experienced system administrators.

Fedora 40 also marks the introduction of Fedora Atomic Desktops, a rebranding for its rpm-ostree based variants, which include Silverblue, Kinoite, Sway, and Budgie​

Key features of Fedora 40 for servers include:

  • Advanced security features with SELinux integration, providing a robust defense against various types of attacks and unauthorized access attempts
  • Regular updates and a short release cycle, ensuring access to the latest software and security patches, typically within six months of upstream releases
  • Amazing performance and resource management, allowing for efficient utilization of hardware resources and optimal server performance
  • Dozens of supported server applications, from web servers and databases to containerization and virtualization technologies
  • Built-in support for the latest networking protocols and standards, ensuring compatibility with modern infrastructure requirements
  • Comprehensive documentation and a large, active community, providing extensive resources for troubleshooting and optimization

Fedora + Ngnix

Nginx, a high-performance web server and reverse proxy server, is particularly well-suited for deployment on Fedora 40.

This synergy between Fedora and Nginx offers several advantages:

  • Easy installation through Fedora's package manager (DNF), simplifying the setup process and ensuring system-wide consistency
  • Excellent compatibility with Fedora's system architecture, resulting in optimal performance and stability
  • Regular updates and security patches, keeping the Nginx installation secure and up-to-date with the latest features
  • Large community support and extensive documentation, providing a wealth of resources for configuration, optimization, and troubleshooting
  • Seamless integration with Fedora's built-in security features, including SELinux, for enhanced protection of web services
  • Support for the latest web technologies and protocols, ensuring that your server can handle modern web applications and traffic patterns

The combination of Fedora 40's robust server capabilities and Nginx's efficient performance creates a powerful and versatile platform for hosting websites and web applications.

This setup is particularly beneficial in scenarios requiring support for multiple sites, as demonstrated in this tutorial. The flexibility of Nginx's configuration, coupled with Fedora's solid foundation, allows for easy scaling and customization to meet diverse hosting needs.

In the following are the required steps on how to install Ngnix on Fedora

Step 1: Install Nginx

Open a terminal and run the following command to install Nginx:

sudo dnf install nginx

Step 2: Start and Enable Nginx

Start the Nginx service and enable it to start on boot:

sudo systemctl start nginx
sudo systemctl enable nginx

Step 3: Configure Firewall

Allow HTTP and HTTPS traffic through the firewall:

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

Step 4: Create Directory Structure for Multiple Sites

Create directories for each website:

sudo mkdir -p /var/www/site1.com/html
sudo mkdir -p /var/www/site2.com/html

Step 5: Set Permissions

Set the correct permissions for the web directories:

sudo chown -R $USER:$USER /var/www/site1.com/html
sudo chown -R $USER:$USER /var/www/site2.com/html
sudo chmod -R 755 /var/www

Step 6: Create Sample Pages

Create a sample index.html for each site:

echo "Welcome to Site 1" > /var/www/site1.com/html/index.html
echo "Welcome to Site 2" > /var/www/site2.com/html/index.html

Step 7: Create Server Blocks

Create Nginx server blocks for each site:

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

Add the following configuration:

server {
    listen 80;
    server_name site1.com www.site1.com;
    root /var/www/site1.com/html;
    index index.html index.htm;

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

Repeat this process for site2.com.

Step 8: Test Nginx Configuration

Check if the Nginx configuration is correct:

sudo nginx -t

Step 9: Restart Nginx

If the configuration test passes, restart Nginx:

sudo systemctl restart nginx

Step 10: Update Local Hosts File (Optional for Testing)

Add entries to your local hosts file for testing:

sudo nano /etc/hosts

Add these lines:

127.0.0.1   site1.com www.site1.com
127.0.0.1   site2.com www.site2.com

Final Thought

You have now successfully installed Nginx on Fedora and configured it to support multiple sites.

Each site can be accessed using its respective domain name. Remember to replace the sample configurations with your actual domain names and content.








Open-source Apps

9,500+

Medical Apps

500+

Lists

450+

Dev. Resources

900+