Atlantic.Net Blog

How to Install Nginx Web Server on Fedora

Nginx, also called engine-ex, is an open-source, high-performance web server used to host a website on the Internet. Nginx is also used as a reverse proxy, load-balancer, caching, and media streaming. It is lightweight, high-performance, and specially used to serve static files. It has an HTTPS capability and is designed for maximum performance and to handle the high-loaded website.

In this post, we will show you how to install the Nginx web server on Fedora 34.

Step 1 – Install Nginx Web Server

By default, the Nginx package is included in the Fedora 34 default repo. You can install it with the following command.

dnf update -y
dnf install nginx

Once Nginx is installed, run the following command to see detailed information about the Nginx package:

rpm -qi nginx

You will get the following output.

Name        : nginx
Epoch       : 1
Version     : 1.22.0
Release     : 1.fc34
Architecture: x86_64
Install Date: Thursday 13 April 2023 11:08:55 PM
Group       : Unspecified
Size        : 154661
License     : BSD
Signature   : RSA/SHA256, Wednesday 25 May 2022 08:56:23 AM, Key ID 1161ae6945719a39
Source RPM  : nginx-1.22.0-1.fc34.src.rpm
Build Date  : Wednesday 25 May 2022 08:36:04 AM
Build Host  : buildhw-x86-05.iad2.fedoraproject.org
Packager    : Fedora Project
Vendor      : Fedora Project
URL         : https://nginx.org
Bug URL     : https://bugz.fedoraproject.org/nginx
Summary     : A high performance web server and reverse proxy server
Description :
Nginx is a web server and a reverse proxy server for HTTP, SMTP, POP3 and
IMAP protocols, with a strong focus on high concurrency, performance and low
memory usage.

Step 2 – Manage the Nginx Service

Nginx service is managed by systemd in Fedora 34. You can use the systemctl command to start, stop, restart, and enable the Nginx service.

To start the Nginx service, run the following command.

systemctl start nginx

To enable the Nginx service, run the following command.

systemctl enable nginx

To stop the Nginx service, run the following command.

systemctl stop nginx

To verify the Nginx status, run the following command.

systemctl status nginx

You will get the Nginx status in the following output.

● nginx.service - The nginx HTTP and reverse proxy server
     Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
    Drop-In: /usr/lib/systemd/system/nginx.service.d
             └─php-fpm.conf
     Active: active (running) since Thu 2023-04-13 23:08:59 EDT; 5s ago
    Process: 6314 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
    Process: 6315 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
    Process: 6316 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
   Main PID: 6317 (nginx)
      Tasks: 3 (limit: 4666)
     Memory: 3.2M
        CPU: 95ms
     CGroup: /system.slice/nginx.service
             ├─6317 nginx: master process /usr/sbin/nginx
             ├─6318 nginx: worker process
             └─6319 nginx: worker process

Step 3 – Access the Nginx Test Page

At this point, Nginx is installed and listens on port 80. You can check it with the following command.

ss -antpl | grep :80

You will get the following output.

LISTEN 0      511          0.0.0.0:80        0.0.0.0:*    users:(("nginx",pid=6319,fd=10),("nginx",pid=6318,fd=10),("nginx",pid=6317,fd=10))
LISTEN 0      511             [::]:80           [::]:*    users:(("nginx",pid=6319,fd=11),("nginx",pid=6318,fd=11),("nginx",pid=6317,fd=11))

Now, open your web browser and access the Nginx test page using the URL http://your-server-ip. You should see the Nginx test page on the following screen.

Nginx test page

Step 4 – Create a Sample Website

Next, create a website directory with the following command.

mkdir /var/www/html/nginxsite

Next, create a simple HTML file inside the website directory.

nano /var/www/html/nginxsite/index.html

Add the following configurations:

<html>
 <head>
  <title>Welcome to Nginx!</title>
 </head>
 <body>
   <h1>Success! The Nginx server block is working!</h1>
 </body>
</html>

Save and close the file, then set the ownership to the website directory.

chown -R nginx:nginx /var/www/html/nginxsite

Step 5 – Create an Nginx Virtual Host

Next, create an Nginx virtual host to host your website on the web.

nano /etc/nginx/conf.d/nginxsite.conf

Add the following configurations:

server {

 listen 80;

 server_name nginx.example.com;
 root /var/www/html/nginxsite/;

  index index.html index.htm;

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

Save and close the file, then edit the Nginx main configuration file.

nano /etc/nginx/nginx.conf

Add the following line below the line http{:

server_names_hash_bucket_size 64;

Save and close the file, then verify the Nginx for any syntax error.

nginx -t

You will get the following output.

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Finally, restart Nginx to apply the changes.

systemctl restart nginx

Step 6 – Verify Nginx Website

Now, open your web browser and access the Nginx website using the URL http://nginx.example.com. You should see the following screen.

nginx virtual hosting test page

Conclusion

Congratulations! You have successfully installed the Nginx web server on Fedora 34. You can now host your own website on the internet using the Nginx web server. You can also deploy Nginx on dedicated server hosting from Atlantic.Net!

Get a $250 Credit and Access to Our Free Tier!

Free Tier includes:
G3.2GB Cloud VPS a Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year