To install nginx as a reverse proxy and load balancer on a CentOS or Red Hat Linux system, you can use the yum
package manager and the install
subcommand.
First, add the nginx repository to your system by creating the /etc/yum.repos.d/nginx.repo
file with the following content:
[nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=0 enabled=1
Next, use the yum
command to install nginx:
sudo yum install nginx
This will install nginx and all the necessary dependencies.
Once nginx is installed, you can configure it as a reverse proxy and load balancer by editing the /etc/nginx/nginx.conf
file. For example, to set up nginx as a reverse proxy for a backend server, you can add the following configuration to the http
block in the nginx.conf
file:
server { listen 80; location / { proxy_pass http://backend; } } upstream backend { server backend1.example.com; server backend2.example.com; }
This will configure nginx to listen on port 80 and proxy incoming requests to the backend servers specified in the backend
upstream block.
To start the nginx service and enable it to start at boot, use the following commands:
sudo systemctl start nginx sudo systemctl enable nginx
This will start nginx and configure it to load balance incoming requests between the backend servers.