Atlantic.Net Blog

How to Install and Configure Nginx Webserver on Oracle Linux 8

Hitesh Jethva
by Atlantic.Net (414 posts) under Tutorials, VPS Hosting
0 Comments

Nginx, pronounced “engine-ex,” is a free and open-source web server used to host websites on the Internet. It is lightweight and high-performance and can be used for reverse proxy, caching, load balancing, media streaming, and more. It is a fast, highly scalable, and highly available web server compared to the Apache web server. It is one of the best web servers in the world. Nginx is the first choice for many websites due to its ability to handle massive connections.

In this post, we will show you how to install the latest Nginx Mainline on Oracle Linux 8.

Prerequisites

  • A server running Oracle Linux 8 on Atlantic.Net Cloud Platform
  • A root password configured on your server

Step 1 – Create Atlantic.Net Cloud Server

First, log in to your Atlantic.Net Cloud Server. Create a new server, choosing Oracle Linux 8 as the operating system with at least 2GB RAM. Connect to your Cloud Server via SSH and log in using the credentials highlighted at the top of the page.

Once you are logged in to your server, run the following command to update your base system with the latest available packages.

dnf update -y

Step 2 – Add an Nginx Repository

By default, the latest Nginx mainline version is not included in the Oracle Linux Appresteam repository. For a production environment, it is always recommended to install the latest version.

First, install the dnf-utils package using the following command:

dnf install dnf-utils -y

Next, create an Nginx repo with the following command:

nano /etc/yum.repos.d/nginx.repo

Add the following lines:

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

Save and close the file, then enable the Nginx Mainline repo using the following command:

yum-config-manager --enable nginx-mainline

Step 3 – Install Nginx Mainline on Oracle Linux 8

Now, install the latest Nginx Mainline package by running the following command:

dnf install nginx

After Nginx is successfully installed, start the Nginx service and enable it to start at system reboot:

systemctl start nginx
systemctl enable nginx

Next, verify the status of Nginx with the following command:

systemctl status nginx

You should get the following output:

● nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since Wed 2022-06-08 12:21:41 EDT; 19s ago
     Docs: http://nginx.org/en/docs/
  Process: 14372 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
 Main PID: 14373 (nginx)
    Tasks: 3 (limit: 23694)
   Memory: 2.8M
   CGroup: /system.slice/nginx.service
           ├─14373 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
           ├─14374 nginx: worker process
           └─14375 nginx: worker process

Jun 08 12:21:41 oraclelinux8 systemd[1]: Starting nginx - high performance web server...
Jun 08 12:21:41 oraclelinux8 systemd[1]: Started nginx - high performance web server.

You can now verify the Nginx version using the following command:

nginx -v

You should see the Nginx version in the following output:

nginx version: nginx/1.22.0

Step 4 – Configure Firewall

By default, Nginx listens on ports 80 and 443. If any firewall is installed and configured to your server, then you will need to allow both ports via firewalld. You can allow them with the following command:

firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https

Next, reload firewalld to apply the changes:

firewall-cmd --reload

Step 5 – Access Nginx Default Page

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

Step 6 – Host a Simple Website with Nginx

First, create a directory to hold the website data with the following command:

mkdir /var/www/html/test.example.com

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

nano /var/www/html/test.example.com/index.html

Add the following HTML code:

<html>
<h1>Welcome to the Example Website!</h1>
</html>

Save and close the file, then change the ownership and permissions of the website directory:

chown -R www-data:www-data /var/www/html/test.example.com/
chmod -R 775 /var/www/html/test.example.com/

Next, create an Nginx virtual host configuration file to define the website path.

nano /etc/nginx/conf.d/test.example.com.conf

Add the following configuration:

server {
listen 80;
server_name test.example.com;
root /var/www/html/test.example.com;
index index.html;
}

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

nano /etc/nginx/nginx.conf

Add the following line below http {:

server_names_hash_bucket_size 64;

Save and close the file, then verify Nginx for any syntax configuration errors:

nginx -t

You should 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

Next, restart the Nginx service to apply the configuration changes:

systemctl restart nginx

Now, open your web browser and verify your website using the URL http://test.example.com. You should see your website page on the following screen:
Verify Nginx

Conclusion

In the above post, we explained how to install the latest Nginx mainline version on Oracle Linux 8. We also explained how to create a new website and host it using the Nginx virtual host. Try it on VPS hosting from Atlantic.Net!

Get A Free To Use Cloud VPS

Free Tier Includes:
G3.2GB Cloud VPS 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


Looking for a Hosting Solution?

We Provide Cloud, Dedicated, & Colocation.

  • Seven Global Data Center Locations.
  • Flexible Private, Public, & Hybrid Hosting.
  • 24x7x365 Security, Support, & Monitoring.
Contact Us Now! Med Tech Award FTC
SOC Audit HIPAA Audit HITECH Audit

Recent Posts

Top 10 Best Cybersecurity Training Services
How to Install Ansible on Oracle Linux 8
How to Install LEMP Server on Oracle Linux 8
How to Install and Configure Apache Webserver on Oracle Linux 8
How to Install and Configure Nginx Webserver on Oracle Linux 8

Get started with 12 months of free cloud VPS hosting

Free Tier includes:
G3.2GB Cloud VPS Server 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


New York, NY

100 Delawanna Ave, Suite 1

Clifton, NJ 07014

United States

San Francisco, CA

2820 Northwestern Pkwy,

Santa Clara, CA 95051

United States

Dallas, TX

2008 Lookout Dr,

Dallas, Texas 75044

United States

Ashburn, VA

1807 Michael Faraday Ct,

Reston, VA 20190

United States

Orlando, FL

440 W Kennedy Blvd, Suite 3

Orlando, FL 32810

United States

Toronto, Canada

20 Pullman Ct, Scarborough,

Ontario M1X 1E4

Canada

London, UK

14 Liverpool Road, Slough,

Berkshire SL1 4QZ

United Kingdom

Resources