业务场景:
对外提供服务,通过域名解析到两台nginx然后转发到业务系统。
说明:
我有两台阿里云服务器,上面部署了nginx,jdk,业务系统,mysql和redis都是在阿里云上买的,所以在这两台服务上不需要部署mysql和redis,若需要部署可以参考我之前的博客,都是实操,亲测可用的!
一、配置https转发
1.找运维申请域名
申请外网域名和LB(比如域名为a.com)
LB的443端口转到服务器 业务服务器1
、业务服务器2
的80端口
2.配置nginx.conf进行转发到业务服务,
由于我的请求为https,所以只关心配置文件中 # HTTPS server相关部分,
找到nginx的安装目录:
比如我的vi /usr/local/nginx/conf/nginx.conf
#user nobody;
worker_processes 2; #nginx调优,可以配置于cpu核数相等,根据具体业务场景来调整
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
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 "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
# iccess_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server