Installing NGINX

Before you can use NGINX for load balancing, you must first install the software and configure the environment.

  1. Install the nginx package on each server

    Run the following command:

    sudo dnf install nginx

    Depending on the intended configuration, you might need to install more modules. The nginx-all-modules metapackage installs all the packages. To display the complete listing of the available modules in the package manager, use the following command:

    sudo dnf search nginx-mod*

    Note that if you intend to do TCP/UDP load balancing, you must install the nginx-mod-stream module package. For example, run the following command:

    sudo dnf install nginx-mod-stream
  2. Configure the firewall to enable access to the services or ports that you want NGINX to handle.

    For example, you would accept incoming TCP requests on port 80 by running the following commands:

    sudo firewall-cmd --zone=zone --add-port=80/tcp
    sudo systemctl reload firewalld
  3. If SELinux is set to enforcing mode on the system, add a rule to allow NGINX to relay HTTP traffic to any configured backend servers.

    Run the following command:

    sudo setsebool httpd_can_network_relay on
  4. Enable and start the nginx service on each server.

    Run the following command:

    sudo systemctl enable --now nginx

    If you change the NGINX configuration, reload the nginx service:

    sudo systemctl reload nginx