Nginx pronounced engine x is a free, open-source, high-performance HTTP and reverse proxy server responsible for handling the load of some of the largest sites on the Internet.
Nginx can be used as a standalone web server, and as a reverse proxy for Apache and other web servers.
Compared to Apache, Nginx can handle a much large number of concurrent connections and has a smaller memory footprint per connection.
This tutorial will teach you how to install and manage Nginx on your CentOS 7 machine.
Before starting with the tutorial, make sure you are logged in as a user with sudo privileges and you don’t have Apache or any other service running on port 80 or 443.
Installing Nginx on CentOS
Follow the steps below to install Nginx on your CentOS server:
- Nginx packages are available in the EPEL repositories. If you don’t have EPEL repository already installed you can do it by typing:
sudo yum install epel-release
- Install Nginx by typing the following yum command:
sudo yum install nginx
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 Importing GPG key 0x352C64E5: Userid : "Fedora EPEL (7) <[email protected]>" Fingerprint: 91e9 7d7c 4a5e 96f1 7f3e 888f 6a2f aea2 352c 64e5 Package : epel-release-7-9.noarch (@extras) From : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7 Is this ok [y/N]:
If that’s the case, type
y and hit
- Once the installation is complete, enable and start the Nginx service with:
sudo systemctl enable nginx
sudo systemctl start nginx
Check the status of the Nginx service with the following command:
sudo systemctl status nginx
The output should look something 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 2020-07-25 15:15:48 UTC; 2s ago Process: 1977 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS) Process: 1975 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS) Process: 1973 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS) Main PID: 1980 (nginx) CGroup: /system.slice/nginx.service ├─1980 nginx: master process /usr/sbin/nginx └─1981 nginx: worker process
- If your server is protected by a firewall you need to open both HTTP (
80) and HTTPS (
Use the following commands to open the necessary ports:
sudo firewall-cmd –permanent –zone=public –add-service=http
sudo firewall-cmd –permanent –zone=public –add-service=https
sudo firewall-cmd –reload
- To verify your Nginx installation, open
http://YOUR_IPin your browser of choice, and you will see the default Nginx welcome page as shown in the image below: