Nginx是一款輕量級的Web 服務(wù)器/反向代理服務(wù)器及電子郵件(IMAP/POP3)代理服務(wù)器,其特點(diǎn)是占用內存少,并發(fā)能力強,是我們在Web開(kāi)發(fā)中最常用的工具之一。那么Nginx反向代理的主要作用有哪些?有幾種常用模式呢?下面一起來(lái)了解下。
Nginx反向代理的主要作用
Nginx配置反向代理時(shí),是安裝在目的主機端,主要用于轉發(fā)客戶(hù)機請求,后臺有多個(gè)http服務(wù)器提供服務(wù),Nginx的功能就是把請求轉發(fā)給后面的服務(wù)器,決定哪臺目標主機來(lái)處理當前請求。
此外,Nginx能提供性能穩定、并且提供配置靈活的轉發(fā)功能。它可以根據不同的正則匹配,采取不同的轉發(fā)策略,并且Nginx對返回結果進(jìn)行錯誤頁(yè)跳轉,異常判斷等。如果被分發(fā)的服務(wù)器存在異常,它可以將請求重新轉發(fā)給另外一臺服務(wù)器,然后自動(dòng)去除異常服務(wù)器。
相關(guān)閱讀:《Nginx反向代理服務(wù)器配置教程》
Nginx反向代理的三種模式
1、基于IP代理
2、基于域名代理
3、基于端口代理
nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
charset utf-8;
include mime.types;
default_type application/octet-stream;
log_format main ‘$remote_addr – $remote_user [$time_local] “$request” ‘
‘$status $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” “$http_x_forwarded_for”‘;
# log_format main ‘remote_addr=$remote_addr:$remote_port, http_x_forwarded_for=$http_x_forwarded_for, proxy_add_x_forwarded_for=$proxy_add_x_forwarded_for ‘;
access_log logs/access_format.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on
# 原始server
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
}
# 引入自定義的server配置
include my-proxy-server.conf;
}
my-proxy-server.conf
基于端口代理
server {
listen 81;
server_name localhost;
location / {
proxy_pass http://192.168.0.153:9091;
proxy_redirect default;
}
location = /50x.html {
root html;
}
}
server {
listen 82;
server_name localhost;
location / {
proxy_pass http://git.itplh.com;
proxy_redirect default;
}
location = /50x.html {
root html;
}
}
# 基于域名代理 gitlocal負載均衡
upstream gitlocal{
server 192.168.0.153:9091;
server 192.168.0.154:9091;
server 192.168.0.155:9091;
}
upstream gitbj{
server git.itplh.con;
}
server {
listen 80;
server_name gitlocal.com;
location / {
proxy_pass http://gitlocal;
proxy_redirect default;
}
location = /50x.html {
root html;
}
}
server {
listen 80;
server_name gitbj.com;
location / {
proxy_pass http://gitbj;
proxy_redirect default;
}
location = /50x.html {
root html;
}
來(lái)源鏈接:https://www.idcspy.com/31442.html
本站聲明:網(wǎng)站內容來(lái)源于網(wǎng)絡(luò ),如有侵權,請聯(lián)系我們,我們將及時(shí)處理。
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。
Copyright ? 2009-2022 56dr.com. All Rights Reserved. 特網(wǎng)科技 特網(wǎng)云 版權所有 特網(wǎng)科技 粵ICP備16109289號
域名注冊服務(wù)機構:阿里云計算有限公司(萬(wàn)網(wǎng)) 域名服務(wù)機構:煙臺帝思普網(wǎng)絡(luò )科技有限公司(DNSPod) CDN服務(wù):阿里云計算有限公司 百度云 中國互聯(lián)網(wǎng)舉報中心 增值電信業(yè)務(wù)經(jīng)營(yíng)許可證B2
建議您使用Chrome、Firefox、Edge、IE10及以上版本和360等主流瀏覽器瀏覽本網(wǎng)站