Nginx is a popular, high-performance, open-source web server and reverse proxy server. It’s known for its stability, simplicity, and low resource usage, making it an excellent choice for various applications. In this guide, we will walk you through the steps on how to install Nginx on Oracle Linux.
Prerequisites
Before you begin, make sure you have the following:
- An Oracle Linux 7 or 8 system (either physical or virtual)
- A user with sudo privileges
- A stable internet connection
How to Install Nginx on Oracle Linux
Update Your System
First, update your system packages to ensure you have the latest software versions. Open a terminal and run the following command:
sudo dnf update -y
Install EPEL Repository
The Extra Packages for Enterprise Linux (EPEL) repository provides additional software packages that are not available in the default Oracle Linux repositories. To install Nginx, you need to enable the EPEL repository on your system. Run the following command:
sudo dnf install epel-release -y
Installing Nginx on Oracle Linux
With the EPEL repository enabled, you can now install Nginx using the following command:
sudo dnf install nginx -y
After the installation is complete, start and enable the Nginx service to ensure it runs automatically after a system reboot:
sudo systemctl start nginx
sudo systemctl enable nginx
Configure Firewall
To allow incoming traffic on HTTP and HTTPS ports, configure the firewall rules with the following commands:
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
Verify Nginx Installation
To confirm that Nginx is up and running, open a web browser and visit your server’s IP address or domain name. You should see the default Nginx welcome page.
Alternatively, you can run the following command to check the Nginx service status:
sudo systemctl status nginx
Configure Nginx on Oracle Linux
Nginx configuration files are stored in the /etc/nginx
directory. The main configuration file is nginx.conf
, while individual site configurations are stored in the conf.d
subdirectory.
To create a new site configuration, create a new file in the conf.d
directory:
sudo nano /etc/nginx/conf.d/your_domain.conf
Replace your_domain
with your actual domain name. Add the following configuration to the file, adjusting the server_name, root, and index directives as necessary:
server {
listen 80;
server_name your_domain.com www.your_domain.com;
root /var/www/your_domain;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
Save and close the file. Next, create the document root directory and a sample index.html
file:
sudo mkdir -p /var/www/your_domain
echo "Hello, Nginx on Oracle Linux!" | sudo tee /var/www/your_domain/index.html
After making changes to the Nginx configuration, always test the configuration for syntax errors with the following command:
sudo nginx -t
If there are no errors, reload Nginx to apply the changes:
sudo systemctl reload nginx
Now visit your domain in a web browser to see your new site.
Conclusion
You have successfully installed and configured Nginx on Oracle Linux. With Nginx running, you can now host various web applications on your server and benefit from the performance and stability of Nginx.
For more advanced configurations, you can explore options like setting up SSL certificates, reverse proxy, load balancing, and caching to enhance your server’s performance and security. Additionally, you may want to learn about other web hosting tools and options available for Oracle Linux, such as Apache, Plesk, and CWP.
Don’t forget to check out other tutorials on our website, like how to create RAID 1 in Ubuntu or how to install Python on Rocky Linux. We hope this guide was helpful, and you now have a better understanding of how to install Nginx on Oracle Linux.