Centos 7.6 configuring nginx reverse proxy load balancing cluster

Keywords: Linux Nginx vim yum OpenSSL

I. Introduction to the experiment

Three centos7 virtual machines are used to build a simple nginx reverse proxy load cluster,

Address and function introduction of three virtual machines

192.168.2.76 nginx load balancer

192.168.2.82 web01 server

192.168.2.78 web 02 server

2. Install nginx software (the following three virtual machines should be operated)
1. Command set of installation dependency package

yum -y install openssl openssl-devel pcre pcre-devel gcc

2. Install nginx package command set

mkdir /app

cd /app

wget -q http://nginx.org/download/nginx-1.6.3.tar.gz

useradd -s /sbin/nologin -M nginx

id nginx
tar xf nginx
-1.6.3.tar.gz cd nginx-1.6.3 ./configure --user=nginx --group=nginx --prefix=/app/nginx --with-http_stub_status_module --with-http_ssl_module make && make install

Some Centos 7.6 does not have the wget command installed, so you need to install it yourself:

yum -y install wget

3. Configuration file
1, (the following operations are performed on web01 and web02)

vim /app/nginx/conf/nginx.conf

Change the configuration file to the following

worker_processes 1;
  events {
    worker_connections 1024;
}
http {
  include mime.types;
  default_type application/octet-stream;
  sendfile on;
  keepalive_timeout 65;
  log_format main '$remote_addr - $remote_user [$time_local] "$request" '
            '$status $body_bytes_sent "http_referer" '
            '"$http_user_agent" " $http_x_forwarded_for"';
server {
  listen 80;
  server_name bbs.dengchuanghai.org;
  location / {
  root html/bbs;
  index index.html index.htm;
  }
  access_log logs/access_bbs.log main;
}

Take out the notes according to the above.

Then save to exit, and enter the following:

web1 server:

mkdir /app/nginx/html/bbs

echo "192.168.2.82 bbs" >>/app/nginx/html/bbs/index.html             

echo "192.168.2.82 bbs.dengchuanghai.org" >> /etc/hosts                     

web2 server:

echo "192.168.2.78 bbs" >>/app/nginx/html/bbs/index.html    

echo "192.168.2.78 bbs.dengchuanghai.org" >> /etc/hosts  

Then start nginx separately

/app/nginx/sbin/nginx -t (Check the configuration file for errors)

/app/nginx/sbin/nginx  start-up

ss -tnlp | grep 80

2. The following operations are performed on nginx load balancer

vim /app/nginx/conf/nginx.conf

Some Centos 7.6 does not have vim command installed. You need to install it yourself:

yum -y install vim-enhanced

Change to the following

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    upstream www_server_pools{
    server 192.168.1.190:80 weight=1;
    server 192.168.1.189:80    weight=1;     
    }
    server {
        listen       80;
        server_name  www.dengchuanghai.org;
        location / {
              proxy_pass http://www_server_pools;
     }
    }
}

Save and exit:

echo "192.168.1.188 www.dengchuanghai,org" >> /etc/hosts

Check syntax

/app/nginx/sbin/nginx -t

Startup service

/app/nginx/sbin/nginx

Enter your proxy IP in the external browser;

Posted by dr_overload on Mon, 02 Dec 2019 10:34:12 -0800