Nginx调度器(反向代理),TCP/UDP调度器
生活随笔
收集整理的這篇文章主要介紹了
Nginx调度器(反向代理),TCP/UDP调度器
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一,nginx反向代理
環境
步驟一: 部署后端Web 服務器web1和web2:以web1為例:
yum -y install gcc pcre-devel openssl-devel yum -y install gcc pcre-devel openssl-devel tar -xf nginx-1.10.3.tar.gz cd nginx-1.10.3 useradd -s /sbin/nologin nginx ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module make make install mv nginx-1.1* /usr/local/nginx/ ln -s /usr/local/nginx/sbin/nginx /sbin/ nginx netstat -antulp |grep nginx echo "192.168.1.100" > /usr/local/nginx/html/index.html二,安裝nginx,修改配置,添加服務器池,實現反向代理功能
1,安裝Nginx
yum -y install gcc pcre-devel openssl-devel cd nginx-1.10.3 useradd -s /sbin/nologin nginx ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module make & make install ln -s /usr/local/nginx/sbin/nginx /sbin/ nginx netstat -antulp | grep nginx2,修改Nginx配置文件
vim /usr/local/nginx/conf/nginx.conf35 #使用upstream定義后端服務器集群,集群名稱隨意(如webserver)36 #使用server定義集群中服務器的IP和端口37 upstream webserver {38 server 192.168.1.100:80;39 server 192.168.1.200:80;40 }41 ... ...52 location / {53 proxy_pass http://webserver;54 #通過proxy_pass將用戶的請求轉發給webserver集群nginx -s reload?
三,客戶端訪問測試
http://192.168.0.2/? ? ?訪問測試刷新出現不同的頁面,配置成功!!
配置upstream服務器集群池屬性
vim /usr/local/nginx/conf/nginx.conf37 upstream webserver {38 server 192.168.1.100 weight=1 max_fails=1 fail_timeout=30;39 server 192.168.1.200 weight=2 max_fails=2 fail_timeout=30;40 server 192.168.1.101 down;41 } 42 #weight設置服務器權重值,默認值為143 #max_fails設置最大失敗次數44 #fail_timeout設置失敗超時時間,單位為秒45 #down標記服務器已關機,不參與集群調度?
配置upstream服務器集群的調度算法
vim /usr/local/nginx/conf/nginx.conf37 upstream webserver {38 ip_hash;39 #通過ip_hash設置調度規則為:相同客戶端訪問相同服務器40 server 192.168.1.100 weight=1 max_fails=1 fail_timeout=30;41 server 192.168.1.200 weight=2 max_fails=2 fail_timeout=30;42 server 192.168.1.101 down;43 }?
# nginx -s reload
客戶端使用瀏覽器訪問代理服務器測試輪詢效果
# curl http://192.168.0.2? ? ? ? ???//使用該命令多次訪問查看效果
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
?
二 ,TCP/UDP調度器
?
================================================================================================
?
?
?
?
?
?
總結
以上是生活随笔為你收集整理的Nginx调度器(反向代理),TCP/UDP调度器的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Mysql搭建主从服务器
- 下一篇: Nginx动态、静态分离,Nginx配置