How to Install Nginx on CentOS 7

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.

Prerequisites

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

Resetting the Root Password in CentOS 8

  • Restart the server and press the e button in the GRUB start menu to edit the startup entry.
  • Add the following parameters at the end of the line starting with linux ($root)/:

rd.break enforcing=0

  • The line should now look something like this:

linux ($root)/vmlinuz-4.18.0-80.11.2.el8_0.x86_64 root=/dev/mapper/centos-root\ ro crashkernel=auto resume=/dev/mapper/centos-swap rd.lvm.lv=centos/root rd.l\ vm.lv=centos/swap rd.break enforcing=0

The parameter rd.break causes the boot process to be interrupted before control is passed from initramfs to systemd. This allows the initramfs prompt to be used for command input, and the parameter enforcing=0 puts SELinux in permissive mode. This saves the later – and possibly very time-consuming – relabeling of the file system, which would be necessary if SELinux were switched off.

  • Press Ctrl+x to boot the system with the changed parameters, and the switch_root prompt of initramfs will be displayed.
  • Since the filesystem under /sysroot/ is mounted with read-only permissions, you must first remount it with write permissions:

switch_root:/# mount -o remount,rw /sysroot

  • Now switch to a chroot environment:

switch_root:/# chroot /sysroot

The prompt changes to sh-4.4#.

  • Now you can change the password via passwd:

sh-4.4# passwd
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

touch /.autorelabel

  • To leave the chroot environment, type the following command:

exit

  • Reboot the server. To do this, enter the following command:

reboot