一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

云服務器|WEB服務器|FTP服務器|郵件服務器|虛擬主機|服務器安全|DNS服務器|服務器知識|Nginx|IIS|Tomcat|

服務器之家 - 服務器技術 - Nginx - Nginx多層代理配置方法

Nginx多層代理配置方法

2019-12-07 16:42215687833 Nginx

這篇文章主要介紹了Nginx多層代理配置方法,此篇文章只給大家介紹nginx的多級代理配置代碼,需要的朋友可以參考下

此篇只說nginx的多級代理配置,不扯其他的.

需求:hba.changyoufun.com-121.201.125.239(gd1)--hk1--co(alphaclash.ggdev.co)  廣東代理--->香港--->加拿大

由于idc機房在加拿大,所以經(jīng)常會配些nginx多級反向代理到國內.(不做代理client就得翻墻,或者說是丟包很嚴重.)

下面的Nginx配置我只寫80的,443的忽略,簡化nginx的配置,參數(shù)也不一一列舉不然太多了.

gd1的反向代理配置:(就是一個反向代理)

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
cat hba.changyoufun.com.conf
server{
 listen 121.201.125.239:80;
 
 server_name hba.changyoufun.com;
 access_log /data/weblogs/hba.changyoufun.com.access.log main;
 index index.html index.php index.htm;
 location / {
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $host;
    proxy_redirect off;
    proxy_read_timeout 600;
    proxy_connect_timeout 600;
    proxy_pass http://hba80;
   }
}
Upstream配置(代理的是hk1的內網(wǎng)ip):
 upstream hba80 {
  server 10.105.3.222:80;  
 }
 upstream hba443 {
  server 10.105.3.222:443;  
 }

hk1的反向代理配置:(也是一個nginx反向代理)

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
cat hba.changyoufun.com.conf
server{
 listen 10.105.3.222:80;
 server_name hba.changyoufun.com;
 access_log /data/weblogs/hba.changyoufun.com.access.log main;
 index index.html index.php index.htm;
 location / {
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $host;
    proxy_redirect off;
    proxy_read_timeout 600;
    proxy_connect_timeout 600;
    proxy_pass http://hba80;
   }
}

Upstream配置(代理的是alphaclash.ggdev.co域名的ip地址):

?
1
2
3
4
5
6
upstream hba80 {
  server 216.66.17.34:80;  
 }
 upstream hba443 {
  server 216.66.17.34:443;  
 }

co機房原先已經(jīng)存在alphaclash.ggdev.co域名的配置,只需要copy一份alphaclash.ggdev.co的nginx配置,將域名替換為hba.changyoufun.com即可.

co的兩份nginx配置:

nginx和php的web版:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
cat hba.changyoufun.com.conf
server{
  listen 216.66.17.34:80;
 server_name hba.changyoufun.com ;
 access_log /data/weblogs/hba.changyoufun.com.access.log main;
 index index.html index.php index.htm;
root /product/clash/alpha/web/htdocs;
location ~ ^/.*(do|php)$ {
  fastcgi_pass php_proxy;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  fastcgi_param PATH_INFO $fastcgi_script_name;
  include /etc/nginx/fastcgi_params;
 }
}
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
cat alphaclash.ggdev.co.conf
server{
  listen 216.66.17.34:80;
 server_name alphaclash.ggdev.co;
 access_log /data/weblogs/alphaclash.ggdev.co.access.log main;
 index index.html index.php index.htm;
root /product/clash/alpha/web/htdocs;
location ~ ^/.*(do|php)$ {
  fastcgi_pass php_proxy;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  fastcgi_param PATH_INFO $fastcgi_script_name;
  include /etc/nginx/fastcgi_params;
 }
}

注釋:其實nginx的代理很簡單,很多時候是沒想明白,既然代理alphaclash.ggdev.co,前面兩級代理配置了這個域名不就ok了?仔細想發(fā)現(xiàn)nginx代理根據(jù)ip:端口找域名,然后在location匹配到的location段再找upstream段,再根據(jù)upstream段的ip+port找下級域名,最后發(fā)現(xiàn)最后一級沒有相匹配的域名就報404了,所以最后一層也要配上相匹配的域名配置.

總結

以上所述是小編給大家介紹的Nginx多層代理配置方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對服務器之家網(wǎng)站的支持!

原文鏈接:http://215687833.blog.51cto.com/6724358/1960815

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 青青草99热这里都是精品 | 千金肉奴隶在线观看 | 好硬好大好浪夹得好紧h | 精品四虎 | 俄罗斯三级在线观看级 | 日韩一区二三区无 | fc2成人免费共享视频 | 亚洲欧美日韩另类在线 | 9l桃色| 日本888 xxxx | sxx免费看观看美女 sss亚洲国产欧美一区二区 | 亚洲国产精品二区久久 | 四虎影视免费观看免费观看 | 美女靠逼免费视频 | 大香焦在线观看 | 亚洲国产精品综合久久一线 | 亚洲天堂网在线观看视频 | 极品虎白女在线观看一线天 | 我的美女奴隶 | 门房秦大爷在线阅读 | 新新电影理论中文字幕 | 精品亚洲麻豆1区2区3区 | 日本特黄一级大片 | 四虎院影永久在线观看 | 国产精品馆 | 日本免费在线播放 | 电车痴汉中文字幕 | 亚洲女同一区二区 | 久久久久嫩草影院精品 | 国产嫩草视频 | 国产高清自拍视频 | 波多野给衣一区二区三区 | 私人黄色| 久久性综合亚洲精品电影网 | 色男人影院 | 国产精品免费观在线 | 亚洲欧洲综合 | 9966国产精品视频 | 白丝女仆被啪到深夜漫画 | 高h折磨调教古代 | 青草视频网站在线观看 |