Install Nginx (Latest Version) on CentOS 7

Nginx [engine x] is an HTTP and reverse proxy server. It is free and open source high-performance web server. Today we will install the latest version of Nginx on CentOS server. It also works on RHEL 7.

Step 1 : Login to Server

At first, we need to login to our server via SSH. Open your terminal and run this command:

ssh root@IPaddress -p PORT

Step 2 : Configure Nginx Repo

Run this command:

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

Now copy and paste this code to nginx.repo file (SHIFT+INS):

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/centos/7/$basearch/
gpgcheck=0

Step 3 : Install Nginx

Run this command to install Nginx:

sudo yum install nginx

Start Nginx server:

sudo systemctl start nginx

Enable Nginx to start at boot:

sudo systemctl enable nginx

Step 4 : Useful Commands

Here’s some useful Nginx commands:

sudo systemctl stop nginx
sudo systemctl restart nginx
sudo systemctl status nginx

Step 5 : Advanced (Firewall)

If you are running Firewall on your server, then run the following commands to allow HTTP and HTTPS traffic:

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

Now open a web browser and type the IP address of your server to see the output.


Software Engineer | Ethical Hacker & Cybersecurity...

Md Obydullah is a software engineer and full stack developer specialist at Laravel, Django, Vue.js, Node.js, Android, Linux Server, and Ethichal Hacking.