Nginx自学手册(一) upstream及fastcgi
2017-04-11 16:47
811 查看
(一)nginx upstream实现负载均衡
Ngx_http_upstream_module模块可实现七层负载均衡,定义的服务器组可被proxy_pass、fastcgi_pass、uwsgi_pass、scgi_pass和memcached_pass所引用,具体可以参考官方文档: http://nginx.org/en/docs/http/ngx_http_upstream_module.html
1,当前的环境:
Nginx upstream IP:192.168.180.2
node1 : 192.168.180.2:8080
node2 : 192.168.180.3:8080
目前两台主机的服务都已经再跑如图:
![](https://oscdn.geek-share.com/Uploads/Images/Content/202006/07/cf4864c9f9b25a0ed75435a4ff25e6e2.png)
![](https://oscdn.geek-share.com/Uploads/Images/Content/202006/07/61bcf26057b2647a14ca2b9b9385357a.png)
2,nginx upstream配置
(1)只定义http段的定义服务器组
3,测试:
把其中一台服务关闭先把192.168.180.2:8080服务关闭,看下能不能调到192.168.180.3这台服务器上
如下图:
![](https://oscdn.geek-share.com/Uploads/Images/Content/202006/07/d53f02ace9e39ec0caf87feac38ade12.png)
![](https://oscdn.geek-share.com/Uploads/Images/Content/202006/07/469130012276a38b2af2aa172df7b72f.png)
可以正常访问说明服务已调到192.168.180.3这台服务器上,负载均衡已起作用。
备注:主要参数说明:
server 192.168.0.30 weight=2;此处的weight为权重,默认为1;
主要算法,rr,wrr,ip_hash等,可在upstream中定义;
server 192.168.0.30 max_files=3 fail_timeout=30s;此处的max_files,fail_timeout为健康状态检测,超过3次未响应,超时30s,就从server列表中移除。
server 192.168.0.30 backup;标记为备份
server 192.168.0.30 down;标记为不可用,与ip_hash算法一同使用
二、Nginx fastcgi
1、fastcgi全称为高速的通用网关接口,是HTTP服务器与动态脚本语言之间通信的接口,其工作模式与反向代理差不多,实现客户端请求的动静分离。
2 配置fastcfi_params
Ngx_http_upstream_module模块可实现七层负载均衡,定义的服务器组可被proxy_pass、fastcgi_pass、uwsgi_pass、scgi_pass和memcached_pass所引用,具体可以参考官方文档: http://nginx.org/en/docs/http/ngx_http_upstream_module.html
1,当前的环境:
Nginx upstream IP:192.168.180.2
node1 : 192.168.180.2:8080
node2 : 192.168.180.3:8080
目前两台主机的服务都已经再跑如图:
![](https://oscdn.geek-share.com/Uploads/Images/Content/202006/07/cf4864c9f9b25a0ed75435a4ff25e6e2.png)
![](https://oscdn.geek-share.com/Uploads/Images/Content/202006/07/61bcf26057b2647a14ca2b9b9385357a.png)
2,nginx upstream配置
(1)只定义http段的定义服务器组
user ftp; worker_processes 3; worker_rlimit_nofile 65535; events { use epoll; worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #include proxy.conf; log_format yundns_log '$server_name $remote_addr [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"'; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log logs/access.log main; access_log on; server_tokens off; sendfile on; tcp_nopush on; server_names_hash_bucket_size 256; client_header_buffer_size 256k; #large_client_header_buffers 4 32k; large_client_header_buffers 4 256k; client_body_buffer_size 256k; client_header_timeout 3m; client_body_timeout 3m; send_timeout 3m; client_max_body_size 50m; keepalive_timeout 120; fastcgi_intercept_errors on; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; #fastcgi_buffer_size 64k; #fastcgi_buffers 8 64k; #fastcgi_busy_buffers_size 128k; #fastcgi_temp_file_write_size 128k; fastcgi_buffer_size 128k; fastcgi_buffers 4 256k; fastcgi_busy_buffers_size 256k; fastcgi_temp_file_write_size 256k; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_comp_level 2; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on; #limit_req_zone $anti_SendSms zone=anti_SendSms:30m rate=1r/m; limit_req_zone $binary_remote_addr zone=anti_SendSms:30m rate=1r/m; upstream guojinbao{ ip_hash; server 192.168.180.2:8080; server 192.168.180.3:8080; } include server/*.conf; }(2)定义虚拟主机段location区段的proxy_pass中服务器组
server { listen 443 ssl http2; server_name localhost; #ssl on; ssl_certificate guojinbao.geotrust.crt; ssl_certificate_key guojinbao.geotrust.key; rewrite ^/invitejoin/(.*)\.htm[l]?$ /register.shtml?$1 last; index index.jsp index.html; root /opt/static/home; location ~ .* { proxy_pass http://guojinbao; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #proxy_set_header X-Forward-For $remote_addr; proxy_set_header Host $host; } }
3,测试:
把其中一台服务关闭先把192.168.180.2:8080服务关闭,看下能不能调到192.168.180.3这台服务器上
如下图:
![](https://oscdn.geek-share.com/Uploads/Images/Content/202006/07/d53f02ace9e39ec0caf87feac38ade12.png)
![](https://oscdn.geek-share.com/Uploads/Images/Content/202006/07/469130012276a38b2af2aa172df7b72f.png)
可以正常访问说明服务已调到192.168.180.3这台服务器上,负载均衡已起作用。
备注:主要参数说明:
server 192.168.0.30 weight=2;此处的weight为权重,默认为1;
主要算法,rr,wrr,ip_hash等,可在upstream中定义;
server 192.168.0.30 max_files=3 fail_timeout=30s;此处的max_files,fail_timeout为健康状态检测,超过3次未响应,超时30s,就从server列表中移除。
server 192.168.0.30 backup;标记为备份
server 192.168.0.30 down;标记为不可用,与ip_hash算法一同使用
二、Nginx fastcgi
1、fastcgi全称为高速的通用网关接口,是HTTP服务器与动态脚本语言之间通信的接口,其工作模式与反向代理差不多,实现客户端请求的动静分离。
2 配置fastcfi_params
相关文章推荐
- Nginx自学手册(五)搭建https服务器
- nginx+nagios,执行命令就报错:upstream prematurely closed FastCGI stdout while reading resp
- Nginx自学手册(六)Nginx+Tomcat实现动静分离
- nginx详解(三)—FastCGI、https、动静分离、proxy、upstream和cache
- [转]Nginx 502 PHP LNMP 502 终极解决方案 完美解决502 用 upstream 和 fastcgi_next_upstream 可以极大缓解
- ┠ Nginx 502 PHP LNMP 502 终极解决方案 完美解决502 用 upstream 和 fastcgi_next_upstream 可以极大缓解 ┨
- Nginx自学手册(四)反向代理和缓存
- Nginx自学手册(五)搭建https服务器
- Nginx自学手册(三)location匹配,rewrite
- Nginx upstream原理分析【1】upstream和FastCGI前篇
- Nginx自学手册(三)location匹配,rewrite
- Nginx反向代理、缓存、 负载均衡、upstream以及fastcgi模块应用
- nginx学习4——nginx的几个配置文件学习nginx.conf、fastcgi.conf
- windows下nginx+fastcgi不能使用file_get_contents/curl/fopen的原因
- freebsd ports安装 nginx+php+mysql+fastcgi配置记录
- Nginx配置中FastCGI的几个命令
- nginx的fastcgi配置
- nginx与php----CGI,FASTCGI,PHP-CGI以及PHP-FPM各公共网关接口介绍
- EXTJS4自学手册——页面控件(表单控件)
- Nginx配置upstream实现负载均衡