Nginx反向代理负载均衡
web服务器与负载均衡服务器分别进行编译安装Nginx软件
mkdir -p /server/tool/
wget http://nginx.org/download/nginx-1.16.1.tar.gz /server/tool/
tar xf nginx-1. tar.gz 解压软件
yum install -y pcre-devel openssl-devel 安装相关依赖包
useradd -M -s /sbin/nologin www 创建管理用户
cd /server/tool/nginx-1.16.1
./configure --prefix=/application/nginx-1.16 --user=www --group=www --with-http_ssl_module --with-http_stub_status_module
make && make install 进行编译安装
[root@web03 ~]# /app/nginx/sbin/nginx -V 查看之前编译安装方法
nginx version: nginx/1.16.1
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/app/nginx-1.16.1 --user=www --group=www --with-http_ssl_module --with-http_stub_status_module
创建nginx软链接
[root@web03 nginx-1.16.1]# ln -s /app/nginx-1.16.1/ /app/nginx [root@web03 nginx-1.16.1]# cd /app/ [root@web03 app]# ll total 4 lrwxrwxrwx. 1 root root 18 Aug 20 15:46 nginx -> /app/nginx-1.16.1/ drwxr-xr-x. 6 root root 4096 Aug 20 15:43 nginx-1.16.1
在web服务器 进行nginx服务测试是否启动运行是否正常
[root@web02 ~]# netstat -lntup |grep nginx tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1191/nginx
进入负载均衡服务器进行远程测试是否正常
[root@fz-05 conf]# curl -H host:www.impkk.com 10.0.0.7/ 10.0.0.7 www.impkk.com [root@fz-05 conf]# curl -H host:www.impkk.com 10.0.0.8/ 10.0.0.8 www.impkk.com [root@fz-05 conf]# curl -H host:www.impkk.com 10.0.0.9/ (10.0.0.9) www.impkk.com
负载均衡服务器配置如下 (设置web服务区块并在location模块加加以调度)
[root@fz-05 conf]# cat nginx.conf worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; upstream fz{ server 10.0.0.7:80; server 10.0.0.9:80; server 10.0.0.8:80; } server { listen 80; server_name localhost; root html; index index.html index.htm; location / { proxy_pass httpo://fz; } } }
进行测试
[root@fz-05 conf]# curl -H host:www.impkk.com 10.0.0.5/index.html 10.0.0.7 www.impkk.com [root@fz-05 conf]# curl -H host:www.impkk.com 10.0.0.5/index.html (10.0.0.9) www.impkk.com [root@fz-05 conf]# curl -H host:www.impkk.com 10.0.0.5/index.html 10.0.0.8 www.impkk.com