
正文
upstream模块介绍
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
upstream模块介绍
Nginx的负载均衡功能依赖于ngx_http_upsteam_module模块,所支持的代理方式包括proxy_pass、fastcgi_pass、memcached_pass等,新版Nginx软件支持的方式所以增加。主要针对proxy_pass代理。
ngx_http_upstream_module模块有允许Nginx定义一组或多组服务组,使用的可以通过proxy_pass代理方式吧网站的请求发送到事先定义好的对应upstream组的名字上,具体写法为proxy_pass http://www_server_pools,期中www_server_pools就是一个uupstream节点服务组名字
ngx_http_upsteam_module模块官方地址:
http://nginx.org/en/docs/http/ngx_http_upstream_module.html#upstream
基本的upstream配置案例
#准备环境
cp /application/nginx/conf/nginx.conf{,.bak.before.lb}
cd /application/nginx/conf/vim /application/nginx/conf/nginx.conf#####web01 web02 web03
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 www.etiantian.org;
location / {
root html/www;
index index.html index.htm;
}
access_log logs/access_www.log main;
}
server {
listen 80;
server_name bbs.etiantian.org;
location / {
root html/bbs;
index index.html index.htm;
}
access_log logs/access_bbs.log main;
}
}###创建环境
mkdir -p /application/nginx/html/{www,bbs}
for dir in www bbs;do echo "`ifconfig eth0|egrep -o "10.0.0.[0-9]+"` $dir" >/application/nginx/html/$dir/bingbing.html;done/application/nginx/sbin/nginx -t
/application/nginx/sbin/nginx -s reloadcurl 10.0.0.7/bingbing.html
curl 10.0.0.8/bingbing.html
curl 10.0.0.9/bingbing.html######lb01负载均衡服务器cd /application/nginx/conf/
cp /application/nginx/conf/nginx.conf{,.bak.before.lb}
cd /application/nginx/conf/vim /application/nginx/conf/nginx.confworker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65; upstream server_pools {
server 10.0.0.7;
server 10.0.0.8;
server 10.0.0.9;
} server {
listen 80;
server_name www.etiantian.org;
location / {
proxy_pass http://server_pools;
}
}
} /application/nginx/sbin/nginx -t /application/nginx/sbin/nginx -s reload#在lb01测试
curl 10.0.0.5/bingbing.htmlcurl 10.0.0.7/bingbing.html
curl 10.0.0.8/bingbing.html
curl 10.0.0.9/bingbing.html
基本的upstream配置案例







