How to install Nginx on CentOS 7

How to install Nginx on CentOS 7

Install Nginx on CentOS 7

Nginx is a free, high-performance, open source web server that is currently available. Nginx is used as a standalone web server or as a reverse proxy server for Apache (or other web servers). This tutorial outlines how to install Nginx on CentOS 7.

Prerequisites

Before starting the installation of Nginx on CentOS 7, a non-root user account with sudo privileges is required on the server.

1. Install Nginx

First, you need to update your system software package to the latest version. Then you can install Nginx.

Enter and Update System Software Packages

sudo yum -y update

Nginx packages for CentOS are provided through the EPEL repository. Enter the following command to install the EPEL repository:

sudo yum install epel-release

Enter to install Nginx

sudo yum install nginx

If this is your first time installing a package via the EPEL repository, you may be prompted to import your EPEL GPG key. You must type == y == and press == Enter == to continue.

Once the installation is complete, enter the following command to enable and start the Nginx server

sudo systemctl enable nginx
    sudo systemctl start nginx

Check the status of the Nginx server by typing

sudo systemctl status nginx

The output looks like this:

● nginx.service - The nginx HTTP and reverse proxy server
      Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
      Active: active (running) since Mon 2018-10-24 18:45:48 UTC; 2s ago
      Process: 1677 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
      Process: 1675 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
      Process: 1673 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
    Main PID: 1680 (nginx)
      CGroup: /system.slice/nginx.service
          ├─1680 nginx: master process /usr/sbin/nginx
          └─1681 nginx: worker process

2. Firewall management

== HTTP == and == HTTPS == Port must be open if server is behind a firewall

Open HTTP port by typing

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

Open HTTPS port by typing

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

Reload the firewall configuration file by typing

sudo firewall-cmd --reload

Check the installation of Nginx by accessing the following URL

http://YOUR_SERVER_IP_ADDRESS

3. Manage Nginx web server operations

You can use the following commands to manage Nginx web server operations.

If you want to make changes to the configuration file and reload the configuration file, use the following command

sudo systemctl reload nginx

To start the Nginx server, enter the following command

sudo systemctl start nginx

To stop the Nginx server, enter the following command

sudo systemctl stop nginx

To restart the Nginx server you can use the following command

sudo systemctl restart nginx

Check the status of the Nginx server by typing

sudo systemctl status nginx

If you want to disable Nginx after startup and start automatically, enter the following.

sudo systemctl disable nginx

And to enable the autostart service after boot, use the following command

sudo systemctl enable nginx

4. Nginx important files and directories

* The root directory of Nginx file is == etc / nginx ==. * The main configuration file for Nginx is available at == etc / nginx / nginx.conf ==. * You need to add the virtual host (server block) configuration file to == etc / nginx / conf.d. * The default server document root directory for web files is located at == / usr / share / nginx / html ==. * == Both access.log == and == error.log == Nginx log files are located in the == / var / log / nginx / == directory.

Conclusion

You learned how to install Nginx on CentOS 7. If you have any questions, don’t forget the comments below.

Sidebar