Share your love
Install NGINX on Centos 7 – Best Web Server
In this article, we want to teach you what Nginx is and show you How to install Nginx on Centos 7. Before we go to install Nginx, let’s see what Nginx is and how it works.
Nginx is open-source software for web serving, reverse proxying, caching, load balancing, media streaming, and more. It started as a web server designed for maximum performance and stability. In addition to its HTTP server capabilities, Nginx can also function as a proxy server for email (IMAP, POP3, and SMTP) and a reverse proxy and load balancer for HTTP, TCP, and UDP servers. And it is more flexible than the Apache HTTP server.
You can now follow the below guide steps provided by the Orcacore website to Install NGINX on Centos 7.
Table of Contents
Steps To Install NGINX on Centos 7
To install Nginx on Centos 7, It’s better to log in to your server as a non-root user with root privileges. To do this, you can check this on the Initial server setup with the Centos 7 article.
Now follow the steps below to complete this guide.
Step 1 – Add Epel Repository repository on Centos 7
First, run the system update with the command below:
sudo yum update -y
For installing Nginx you should add the Centos 7 EPEL repository first with the following command:
sudo yum install epel-release -y
Step 2 – Command To Install Nginx on Centos 7
Now you can install Nginx with the following command:
sudo yum install nginx
Answer yes to install. Then, start Nginx on Centos 7 with the following command:
sudo systemctl start nginx
Also, you can enable your service to start on boot with the command below:
sudo systemctl enable nginx
Step 3 – Configure Firewall for Nginx on Centos 7
If you are running a firewall you should allow HTTP and HTTPS traffic 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
Note: If you haven’t firewalld first install it then run the commands above.
sudo yum install firewalld -y
Start and enable firewalld with the following command:
# sudo systemctl start firewalld
# sudo systemctl enable firewalld
Note: Don’t forget to run the commands above after the firewalld installation.
Step 4 – Verify Nginx Web Server Installation
At this point, you need your server’s IP address. You can find your public IP address by running the command below:
ip addr
In your output, the eth0 interface is what we want. Run the following command to get your IP address:
ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'
Now you can test by visiting your server’s public IP address in your web browser.
http://server_domain_name_or_IP/
Here you will see the default CentOS 7 Nginx web page in your web browser. If you see the page your web browser is correctly installed and working.
Tips: If you want to secure your web server with Let’s Encrypt, you can check this guide on Secure Nginx with Let’s Encrypt on CentOS 7.
Conclusion
At this point, you have learned what Nginx is and how it works and you can easily use Linux commands to install Nginx on Centos 7 server. It is a great web server that you can use for web serving, reverse proxying, caching, load balancing, media streaming, and more.
Hope you enjoy it. Also, you may like these articles:
Install Varnish Cache for Nginx on Centos 7
Check Nginx Version Installed on Linux Terminal
Configure Nginx as a load balancer
FAQs
What is the official NGINX repository for CentOS 7, and how do I enable it?
To install the Nginx web server on Centos 7, you must add the Epel repository to your server, then, you can simply install and enable your web server:sudo yum install epel-release -y
sudo yum install nginx
sudo systemctl start nginx
sudo systemctl enable nginx
How do I secure NGINX with SSL (HTTPS) on CentOS 7?
You can easily use the Let’s Encrypt to secure your web server. We have mentioned it in the guide steps. Use the provided steps to secure Nginx.
How do I open firewall ports for NGINX on CentOS 7?
You can easily open the HTTP and HTTPS traffic through your firewall with the commands below:# sudo firewall-cmd --permanent --zone=public --add-service=http
# sudo firewall-cmd --permanent --zone=public --add-service=https
# sudo firewall-cmd –reload