nginx负载均衡
2019-10-10 11:24 unique-yichen 阅读(128) 评论(0) 收藏 举报nginx负载均衡配置
Nginx负载均衡功能需要使用upstream模块
工作流程:
用户发起请求 -ànginx接受请求à根据nginx配置通过反向代理转发给后端web服务器处理
安装:
准备三台web服务器,IP自己配置,这边设置为如下
server 192.168.18.252;
server 192.168.18.253;
用来安装Apache
server 192.168.18.150
用来安装Nginx
分别在两台web服务器上安装Apache
yum -y install httpd
service httpd start
新建测试页面
vim /var/www/html/index.html
内容如下:
<h1>This is web1<h1>
<h1>This is web1<h1>
关闭防火墙
service iptables stop
分别访问两台web服务器,测试是否可以访问到
Nginx安装
Nginx环境:
系统环境:centos6.5_x64
Nginx版本:nginx-1.4.7.tar.gz
安装:
安装依赖包
# yum -y install gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel
# tar zxf nginx-1.4.7.tar.gz
# cd nginx-1.4.7
# ./configure --prefix=/usr/local/nginx
# make && make install
具体配置:
修改配置:vim /usr/local/nginx/conf/nginx.conf
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream vfast {
server 192.168.18.252; 后端的真实web服务器
server 192.168.18.253; 后端的真实web服务器
}
server {
listen 80;
server_name localhost;
location / {
# root html;
# index index.html index.htm;
proxy_pass http://vfast; 调用的upstream 定义的vfast
}
}
}
关闭防火墙:
services iptables stop
访问:http://192.168.18.151 查看时候可以看到后端的web1和web2
nginx负载均衡配置
Nginx负载均衡功能需要使用upstream模块
工作流程:
用户发起请求 -ànginx接受请求à根据nginx配置通过反向代理转发给后端web服务器处理
安装:
准备三台web服务器,IP自己配置,这边设置为如下
server 192.168.18.252;
server 192.168.18.253;
用来安装Apache
server 192.168.18.150
用来安装Nginx
分别在两台web服务器上安装Apache
yum -y install httpd
service httpd start
新建测试页面
vim /var/www/html/index.html
内容如下:
<h1>This is web1<h1>
<h1>This is web1<h1>
关闭防火墙
service iptables stop
分别访问两台web服务器,测试是否可以访问到
Nginx安装
Nginx环境:
系统环境:centos6.5_x64
Nginx版本:nginx-1.4.7.tar.gz
安装:
安装依赖包
# yum -y install gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel
# tar zxf nginx-1.4.7.tar.gz
# cd nginx-1.4.7
# ./configure --prefix=/usr/local/nginx
# make && make install
具体配置:
修改配置:vim /usr/local/nginx/conf/nginx.conf
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream vfast {
server 192.168.18.252; 后端的真实web服务器
server 192.168.18.253; 后端的真实web服务器
}
server {
listen 80;
server_name localhost;
location / {
# root html;
# index index.html index.htm;
proxy_pass http://vfast; 调用的upstream 定义的vfast
}
}
}
关闭防火墙:
services iptables stop
访问:http://192.168.18.151 查看时候可以看到后端的web1和web2
浙公网安备 33010602011771号