nginx负载均衡设置

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配置雷同。

你可能感兴趣的:(nginx)