码迷,mamicode.com
首页 > 其他好文 > 详细

keepalived+nginx负载均衡反向代理

时间:2018-03-09 17:52:15      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:nginx-proxy llinux

keepalived配置

vrrp_script chk_http_port {
    script "/root/check_nginx_pid.sh"
    interval 2                          #(检测脚本执行的间隔)
    weight 2
}
vrrp_instance VI_1 {
    #备用服务器上为 BACKUP
    state MASTER
    #绑定vip的网卡为ens33,你的网卡和阿铭的可能不一样,这里需要你改一下
    interface ens33
    virtual_router_id 52
    #备用服务器上为90
    priority 90
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    track_script {
    chk_http_port            #(调用检测脚本)
    }
    virtual_ipaddress {
        192.168.198.24
    }
}

nginx反向代理配置:
user nginx;
worker_processes 2;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

events {
use epoll;
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;
log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘

                   ‘$status $body_bytes_sent "$http_referer" ‘

                   ‘"$http_user_agent" "$http_x_forwarded_for"‘;
access_log    /var/log/nginx/access.log main;
#sendfile on;
tcp_nopush      on;
tcp_nodelay     on;
keepalive_timeout  65;
 gzip  on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
 client_header_buffer_size    1k;
large_client_header_buffers  4 4k;

upstream proxy_test {
server 192.168.198.144:80 weight=4 max_fails=2 fail_timeout=30s; #如果你要测试,把这里换成你自己要代理后端的ip
server 192.168.198.145:80 weight=9 max_fails=2 fail_timeout=30s;
#ip_hash; #当负载两台以上用ip来hash解决session的问题,一台就别hash了。
}
server {
listen 80;
server_name www.mysvr1.com;
location / {
proxy_pass http://proxy_test; #这里proxy_test是上面的负载的名称,映射到代理服务器,可以是ip加端口, 或url
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~ .(html|php|jsp|jspx|dp)?$
{
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://proxy_test; #转向tomcat处理
}
}
}

keepalived+nginx负载均衡反向代理

标签:nginx-proxy llinux

原文地址:http://blog.51cto.com/wsw26/2084639

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!