Nginx反向代理的主要作用 Nginx反向代理三種模式介紹

Nginx是一款輕量級的Web 服務器/反向代理服務器及電子郵件(IMAP/POP3)代理服務器,其特點是佔用內存少,併發能力強,是我們在Web開發中最常用的工具之一。那麼Nginx反向代理的主要作用有哪些?有幾種常用模式呢?下面一起來了解下。

Nginx反向代理的主要作用

Nginx配置反向代理時,是安裝在目的主機端,主要用於轉發客戶機請求,後臺有多箇http服務器提供服務,Nginx的功能就是把請求轉發給後面的服務器,決定哪臺目標主機來處理當前請求。

此外,Nginx能提供性能穩定、並且提供配置靈活的轉發功能。它可以根據不同的正則匹配,採取不同的轉發策略,並且Nginx對返回結果進行錯誤頁跳轉,異常判斷等。如果被分發的服務器存在異常,它可以將請求重新轉發給另外一臺服務器,然後自動去除異常服務器。

相關閱讀:《Nginx反向代理服務器配置教程》

Nginx反向代理的三種模式

、基於IP代理

2、基於域名代理

3、基於端口代理

nginx.conf

woke_pocesses  ;

eents {

woke_connections  024;

}

http {

chset utf-8;

include       mime.types;

defult_type  ppliction/octet-stem;

log_fomt  min  ̺$emote_dd R $emote_use [$time_locl] “$equest̶ ̺

̺$sttus $body_bytes_sent “$http_efee̶ ̺

̶̺$http_use_gent̶ “$http_x_fowded_fo̶̺;

# log_fomt  min  ̺emote_dd=$emote_dd:$emote_pot, http_x_fowded_fo=$http_x_fowded_fo, poxy_dd_x_fowded_fo=$poxy_dd_x_fowded_fo ̺;

ccess_log  logs/ccess_fomt.log  min;

sendfile    on;

#tcp_nopush     on;

#keeplie_timeout  0;

keeplie_timeout  65;

#gzip  on

# 原始see

see {

listen   80;

see_nme  loclhost;

loction / {

oot   html;

index  index.html index.htm;

}

}

# 引入自定義的see配置

include my-poxy-see.conf;

}

my-poxy-see.conf

基於端口代理

see {

listen   8;

see_nme  loclhost;

loction / {

poxy_pss http://92.68.0.53:909;

poxy_ediect defult;

}

loction = /50x.html {

oot   html;

}

}

see {

listen 82;

see_nme  loclhost;

loction / {

poxy_pss http://git.itplh.com;

poxy_ediect defult;

}

loction = /50x.html {

oot   html;

}

}

# 基於域名代理 + gitlocl負載均衡

upstem gitlocl{

see 92.68.0.53:909;

see 92.68.0.54:909;

see 92.68.0.55:909;

}

upstem gitbj{

see git.itplh.con;

}

see {

listen  80;

see_nme  gitlocl.com;

loction / {

poxy_pss http://gitlocl;

poxy_ediect defult;

}

loction = /50x.html {

oot   html;

}

}

see {

listen       80;

see_nme  gitbj.com;

loction / {

poxy_pss http://gitbj;

poxy_ediect defult;

}

loction = /50x.html {

oot   html;

}