How To Install Nginx on Centos 7

How To Install Nginx on Centos 7

Update The Packages

update your system packages with the update command

sudo yum update -y

Installing EPEL Repository

we can install nginx on centos through epel repository. So first install epel repository then we can install nginx on centos.

EPEL stands for Extra Packages for Enterprise Linux is open source and free community-based repository by Fedora. it will provide packages for Linux distributions such as CentOS.

install epel repository on centos using below command

sudo yum install epel-release -y

after installing epel-release you can verify it with ‘yum repolist’ command it will list all available repositories on your system. in that list you can find epel-release.

Install Nginx on centos 7

after installing epel repository in your machine install nginx with following commands.

sudo yum install nginx -y

Start Nginx Service in Centos 7

verify is nginx is running or not by using status command

sudo systemctl status nginx
 
[root@ip-172-31-39-131 ~]# systemctl status nginx
? nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2019-06-18 16:20:37 UTC; 3s ago
  Process: 29363 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 29360 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 29359 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 29365 (nginx)
   CGroup: /system.slice/nginx.service
           +-29365 nginx: master process /usr/sbin/nginx
           +-29366 nginx: worker process

Jun 18 16:20:37 ip-172-31-39-131.us-east-2.compute.internal systemd[1]: Start...
Jun 18 16:20:37 ip-172-31-39-131.us-east-2.compute.internal nginx[29360]: ngi...
Jun 18 16:20:37 ip-172-31-39-131.us-east-2.compute.internal nginx[29360]: ngi...
Jun 18 16:20:37 ip-172-31-39-131.us-east-2.compute.internal systemd[1]: Faile...
Jun 18 16:20:37 ip-172-31-39-131.us-east-2.compute.internal systemd[1]: Start...
Hint: Some lines were ellipsized, use -l to show in full.

here nginx is active (running) if it is not running in your machine, start nginx service with start command.

sudo systemctl start nginx

add nginx ports to firewall

by default nginx is running port 80 for http and port 443 for https access.

if you are using firewalld in your machine then add nginx ports to this firewalld using below 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 are using aws ec2 instances open 80,443 ports in inbound rules in security groups.

Access Nginx in Browser:

you can access nginx webpage by entering IP address of your machine in the browser.

enter http://ip

 

  • install nginx on centos 7
  • nginx installation on centos 7
  • nginx installation
  • how to install nginx on centos 7

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *