In today’s modern web environment, web servers play a critical role in delivering content to users across the globe. One popular web server is NGINX, which is known for its high performance, stability, and low resource consumption. In this guide, we will walk you through the process of how to install and configure NGINX on Scientific Linux.
Table of Contents
- Introduction to NGINX
- Prerequisites
- Installing NGINX
- Configuring NGINX
- Managing the NGINX Service
- Setting up a Reverse Proxy
- Conclusion
How to Install and Configure NGINX on Scientific Linux
Introduction to NGINX
NGINX is an open-source web server that also functions as a reverse proxy, load balancer, and HTTP cache. It is highly popular due to its lightweight architecture and ability to handle a large number of concurrent connections efficiently. Many web developers prefer NGINX over other web servers, such as Apache, because of its performance and ease of configuration.
Prerequisites
Before you start installing NGINX on Scientific Linux, make sure that you have:
- A system running Scientific Linux
- Access to a user account with sudo privileges
- An active internet connection
It’s also recommended to have basic knowledge of Linux commands and text editors like nano or vim for editing configuration files.
Installing NGINX on Scientific Linux
Follow these steps to install NGINX on Scientific Linux:
- Update your system: First, make sure your system is up-to-date by running the following command:sql
sudo yum update
Install the EPEL repository: The Extra Packages for Enterprise Linux (EPEL) repository provides additional software packages for Scientific Linux. To install the EPEL repository, run:
sudo yum install epel-release
Install NGINX: Now that the EPEL repository is installed, you can install NGINX using the following command:
sudo yum install nginx
Enable and start the NGINX service: To enable the NGINX service to start automatically at boot, run:
sudo systemctl enable nginx
Then, start the NGINX service using:
sudo systemctl start nginx
Verify the installation: To confirm that NGINX is running, open your web browser and visit http://your_server_ip
. You should see the NGINX welcome page.
Configuring NGINX on Scientific Linux
Now that NGINX is installed, let’s configure it to serve a simple HTML page. Create a new directory for your website:
sudo mkdir -p /var/www/my_website
Create an index.html file inside the newly created directory:
sudo nano /var/www/my_website/index.html
Add the following content to the index.html file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Welcome to My Website</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>Welcome to my NGINX-powered website on Scientific Linux.</p>
</body>
</html>
After adding the content, save and exit the file.
Configure NGINX server block on Scientific Linux
To configure NGINX to serve your website, create a new server block configuration file:
sudo nano /etc/nginx/conf.d/my_website.conf
Add the following content to the my_website.conf
file:
server {
listen 80;
server_name my_website.com www.my_website.com;
root /var/www/my_website;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
Replace my_website.com
and www.my_website.com
with your domain name. Save and exit the file.
Test and restart NGINX on Scientific Linux
Test the NGINX configuration to ensure there are no syntax errors:
sudo nginx -t
If the test is successful, restart NGINX to apply the changes:
sudo systemctl restart nginx
Adjust firewall settings on Scientific Linux
If you have a firewall enabled on your Scientific Linux system, you’ll need to allow HTTP traffic through it. For example, if you’re using firewalld, you can run the following commands:
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --reload
Test your website
Open a web browser and enter your domain name (e.g., http://my_website.com
). You should see the “Hello, World!” message from your index.html
file.
Congratulations! You’ve successfully installed and configured NGINX on Scientific Linux to serve your website.
For further reading on NGINX and related topics, check out these articles:
- How to set up Nginx as a reverse proxy for Apache on Arch Linux
- How to set up a bridged network for KVM
- How to install and configure Bacula on Arch Linux
- How to install and configure rsync on Arch Linux
- How to install and configure Zabbix on Arch Linux
With NGINX up and running, you can now host multiple websites, set up load balancing, or use it as a reverse proxy for other web servers like Apache. The possibilities are endless, so keep exploring and enhancing your web server skills on Scientific Linux.