Subscribe to our RSS feed to get alerted every time SUBSCRIBE!

How to Set Up NGINX Web Server on AlmaLinux / Rocky Linux

NGINX is the high performance web server and reverse proxy server. The first version of Red Hat version 8 family in which the default repository contains NGINX packages by default . The NGINX can be used as a Web Server it has very low foot printing. The NGINX can run in production environment by installing it on your respected enterprise Linux.

1. Check whether the NGINX packages is installed or not

 rpm -q nginx

2. Install the NGINX package using DNF package manager

 dnf install nginx -y

3. As soon as installation completes start the services of NGINX

 systemctl start nginx

4. Make sure you have enabled the services of NGINX web server. So that it will survive during boot.

 systemctl enable nginx

It will show given output

ln -s '/usr/lib/systemd/system/nginx.service' '/etc/systemd/system/multi-
user.target.wants/nginx.service'

5. Add the service http and https ports in firewalld firewall so that website will accessible publicly.

 firewall-cmd --permanent --add-service={http,https}

It will show given output

success

6. When done reload the firewall to flush old rules and activate the new rules.

 firewall-cmd --reload

It will show the given output

Success

Configure NGINX

7. Change the webroot directory to the /usr/share/nginx/html

 cd /usr/share/nginx/html/

8. Create a index.html file for checking the nginx webserver is working or not.

 vim index.html

Add the given line

<center><h4>My TechBrown Website</h4></center>

9. Change Current Working Directory to /etc/nginx/conf.d/

 cd /etc/nginx/conf.d/

10. Create a configuration file with  your website name.

 vim techbrown.com.conf

Add the given lines to the file.

server {
        listen 80;
        listen [::]:80;

        root /usr/share/nginx/html;
        index index.html index.htm;

        server_name server.techbrown.com;

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

11. Check and verify the correct configuration file.

 nginx -t

It will show given output

Syntax OK

12. When all done you need to restart the NGINX services. To make the changes in effect.

 systemctl restart nginx

13. Reload the firewalld firewall to remove old firewall rules and refresh it new one.

 firewall-cmd --reload

14. When done checking the website using web browser whether is displayed on web browser or not.

 firefox http://server.techbrown.com

Congratulations now you have installed the NGINX web server on Enterprise Linux.