(内网192.168.199.5)
+-----------VIP----------+
| |
| |
Master Backup
192.168.199.90 192.168.199.57
+----------+ +----------+
| HAProxy | | HAProxy |
|nginx(SSL)| |nginx(SSL)|
|keepalived| |keepalived|
+----------+ +----------+
|
v
192.168.199.88/89
+----------+
| multiple |
| NGINXs |
+----------+
|
v
+--------+---------+
| | |
| | |
v v v
+------+ +------+ +------+
| WEB1 | | WEB2 | | WEB3 |
+------+ +------+ +------+
+--------+ HTTP :80 +----------+
| client | --------------------------------> | |
| | | haproxy, |
+--------+ +---------+ | 1 or 2 |
/ / HTTPS | Nginx | HTTP :80 | listening|
<________/ ---------> | (SSL) | ---------> | ports |
| | | |
+---------+ +----------+
yum install libev-devel openssl-devel
cd /usr/local/src
wget http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.24.tar.gz
git clone https://github.com/cbonte/haproxy-patches.git
tar zxvf haproxy-1.4.24.tar.gz
cd haproxy-1.4.24
patch -p1 < /usr/local/src/haproxy-patches/proxy-protocol/haproxy-1.4-proxy-protocol.patch
make TARGETlinux2628 USE_EPOLL1 ARCHx86_64 && make install
cp /usr/local/src/haproxy-1.4.24/haproxy /usr/sbin/
cp examples/haproxy.init /etc/init.d/haproxy
chmod +x /etc/init.d/haproxy
chkconfig --add haproxy
chkconfig haproxy on
vim /etc/haproxy/haproxy.cfg
global
log 127.0.0.1 local0
log 127.0.0.1 local1 debug
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 45000
user haproxy
group haproxy
daemon
nbproc 12
stats socket /var/lib/haproxy/stats
defaults
mode http
log global
balance roundrobin
option httplog
option dontlognull
option http-server-close
option forwardfor header X-Real-IP
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
timeout http-keep-alive 10s
timeout check 10s
maxconn 45000
stats enable
stats uri /stats
stats realm Haproxy\ Statistics
stats auth username:password
monitor-uri /monitor
frontend http-in :80
reqdel X-Real-IP
reqadd X-Forwarded-Proto:\ http
default_backend http-load-balancer
frontend https-in
bind 127.0.0.1:8443
reqadd X-Forwarded-Proto:\ https
default_backend http-load-balancer
backend http-load-balancer
server lb-1 192.168.199.88:80 maxconn 10000 check port 80
server lb-2 192.168.199.89:80 maxconn 10000 check port 80
user nginx;
worker_processes 12;
error_log logs/error.log crit;
pid logs/nginx.pid;
worker_rlimit_nofile 30000;
events {
use epoll;
worker_connections 51200;
}
http {
include mime.types;
default_type application/octet-stream;
include options.conf;
include proxy.conf;
include l99.com/*.conf;
}
server {
listen 443;
ssl on;
ssl_certificate /usr/local/nginx/conf/l99.com/lifeix-l99.crt;
ssl_certificate_key /usr/local/nginx/conf/l99.com/lifeix-l99.key;
ssl_client_certificate /usr/local/nginx/conf/l99.com/lifeix-dvroot.crt;
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
ssl_prefer_server_ciphers on;
default_type text/plain;
access_log logs/access.www.ssl.l99.com.log main;
error_log logs/error.www.ssl.l99.com.log;
server_name www.l99.com;
if ($request_uri ~ update.php) {
rewrite /(.*)$ http://www.L99.com/timeline.action last;
}
location / {
proxy_cache off;
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_ignore_headers Expires Cache-Control;
proxy_store off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
more_clear_headers "Cache-Control";
add_header Cache-Control "no-cache,max-age0";
proxy_pass http://127.0.0.1:8443;
}
}
service haproxy restart
service nginx restart
openssl s_client -connect 192.168.199.90:443 -servername l99.com
telnet 192.168.199.90 80
GET / HTTP/1.1
Host: www.L99.com
log_format main '$http_x_forwarded_proto $http_x_real_ip $remote_addr $host $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" "$http_user_agent" '
'$request_time $upstream_response_time $pipe "$gzip_ratio"';
https 192.168.199.15 192.168.199.90 www.l99.com - [04/Oct/2013:17:02:33 +0800] "GET /skin/recharge/images/paybtn_bg.jpg HTTP/1.1" 304 0 "https://www.l99.com/Recharge_pay.action" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.76 Safari/537.36" 0.007 0.006 . "-"
! Configuration File for keepalived
global_defs {
router_id LVS_DEVEL
}
vrrp_script chk_haproxy {
script "killall -0 haproxy"
interval 2
weight 2
}
vrrp_script chk_nginx {
script "killall -0 nginx"
interval 2
weight 2
}
vrrp_instance VI_1 {
interface eth0
state MASTER
virtual_router_id 51
priority 101
virtual_ipaddress {
192.168.199.5
}
track_script {
chk_haproxy
chk_nginx
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?