标签:
思路,前段使用硬件负载均衡 banggoo ,将访问负载到nginx,nginx 再将请求反向代理到后端的tomcat上。
服务器一共购买了4台,其中2台作为数据库服务器,另外两台使用虚拟机,每台服务器虚拟5台服务器。
每台服务器配置、操作系统、分区、主机名、IP地址、交换机接口划分
/etc/sysctl.conf
vm.swappiness=10
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_synack_retries = 2
vm.overcommit_memory = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_timestamps = 1
net.ipv4.tcp_tw_recycle = 0
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 1800
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.ip_local_port_range = 10000 65000
/etc/security/limits.conf
* soft nofile 102400
* hard nofile 102400
安装Nginx
configure arguments: --prefix=/usr/local/nginx/ --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module
Nginx 部分修改配置
worker_processes 4;
events {
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 $request_time {$upstream_addr $upstream_status $upstream_http_content_length $upstream_response_time} ‘
‘"$http_x_real_ip" "$http_x_forwarded_for" "$host"‘;
access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
upstream dealer {
ip_hash;
server 192.168.1.54:8081;
server 192.168.1.64:8081;
}
upstream shop{
ip_hash;
server 192.168.1.55:8081;
server 192.168.1.65:8081;
}
upstream platform{
ip_hash;
server 192.168.1.56:8081;
server 192.168.1.66:8081;
}
server {
listen 80 default;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
}
server {
listen 80;
server_name backend;
access_log logs/backend.access.log main;
location / {
proxy_pass http://platform/;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass_header User-Agent;
proxy_set_header Host $host;
allow 192.168.0.0/16;
deny all;
}
}
server {
listen 443 ssl;
server_name dealer.tb.com;
access_log logs/dealer.access.log main;
server_tokens off;
ssl_certificate /usr/local/nginx/conf/server_2019.crt;
ssl_certificate_key /usr/local/nginx/conf/server_2019.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
rewrite ^/$ /dealerShop/ redirect;
location / {
proxy_pass http://dealer/;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass_header User-Agent;
proxy_set_header Host $host;
}
location /platform/captcha/getCaptchaImg.do {
proxy_pass http://platform;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass_header User-Agent;
proxy_set_header Host $host;
}
}
server {
listen 443 ssl;
server_name shop.tb.com;
access_log logs/shop.access.log main;
server_tokens off;
ssl_certificate /usr/local/nginx/conf/server_2019.crt;
ssl_certificate_key /usr/local/nginx/conf/server_2019.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
rewrite ^/$ /payonline/ redirect;
location / {
proxy_pass http://shop/;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass_header User-Agent;
proxy_set_header Host $host;
}
location ~ /payonline/paySuccess {
if ( $uri ~ ([\w]+.xhtml)$ ) {
set $d_path $1;
rewrite .xhtml /payonline/#/$d_path redirect;
}
proxy_pass http://shop;
}
location ~ /payonline/payFail {
if ( $uri ~ ([\w]+.xhtml)$ ) {
set $d_path $1;
rewrite .xhtml /payonline/#/$d_path redirect;
}
proxy_pass http://shop;
}
location ~ /payonline {
if ( $uri ~ ([\w]+.xhtml)$ ) {
set $d_path $1;
rewrite .xhtml$ /payonline/#/$d_path redirect;
}
proxy_pass http://shop;
}
}
server {
listen 80;
listen 443 ssl;
server_name tmail.tb.com;
access_log logs/tmail.access.log main;
server_tokens off;
ssl_certificate /usr/local/nginx/conf/server_2019.crt;
ssl_certificate_key /usr/local/nginx/conf/server_2019.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
rewrite ^/$ /cherryHomePage/home.html redirect;
location / {
proxy_pass http://dealer/;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass_header User-Agent;
proxy_set_header Host $host;
}
}
}
标签:
原文地址:http://www.cnblogs.com/raindsky/p/5730399.html