nginx负载均衡设置

本文详细介绍了Nginx负载均衡配置的具体实现,包括如何设置服务器池、权重分配、SSL证书配置及HTTPS请求转发等关键步骤。通过实例展示了如何在分布式服务器上进行有效的负载均衡,确保系统的稳定性和高效性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

upstream smallapi_staging_slb {
	ip_hash;
	server 192.168.0.1:8090 weight=2;#根据实际情况设置
	server 192.168.0.2:8090 weight=2;#根据实际情况设置
	server 192.168.0.3:8090 weight=1;#根据实际情况设置
}

# 接口请求地址 代理转发
server {
	listen 443 ssl;
	server_name staging.xxx.net;
	index index.html index.htm index.php default.html default.htm default.php;
	root  /home/xxx_staging_deploy/current/wap;
	ssl  on;
	ssl_certificate      /usr/local/nginx/conf/staging_ssl/2198692_staging.xxx.net.pem;
	ssl_certificate_key  /usr/local/nginx/conf/staging_ssl/2198692_staging.xxx.net.key;
	ssl_session_timeout  5m;
	ssl_protocols  TLSv1.1 TLSv1.2;
	ssl_ciphers HIGH:!ADH:!MD5:!RC4;
	ssl_prefer_server_ciphers on;
	#重定向
	location / {
		proxy_pass http://smallapi_staging_slb;
		proxy_set_header Host $host;
		proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-Proto https;
	}
}

# 分布式服务器 192.168.0.1和192。168.0.2和192.168.0.3均设置一遍
server {
	listen 8090;
	index index.html index.htm index.php default.html default.htm default.php;
	root  /home/xxx_staging_deploy/current/wap;
	location /{
		
	}
	include none.conf;
	error_page   404   /404.php;
	location ~ [^/]\.php(/|$) {
		try_files $uri =404;
		fastcgi_pass  unix:/tmp/php72-cgi.sock;
		fastcgi_index index.php;
		include fastcgi.conf;
	}
}

先插入代码段,然后解释下。ip都让我换成19.168.0.x了。负载转发主要做在192.168.0.1和192.168.0.2和192.168.0.3,均都在8090端口。因为地址为https访问,所以特别注意proxy_set_header X-Forwarded-Proto https; 。配置中的192.168.0.1为负载服务器,本身也为转发服务器。192.168.0.2和192.168.0.3的nginx配置雷同。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值