此篇只說(shuō)nginx的多級(jí)代理配置,不扯其他的.
需求:hba.changyoufun.com-121.201.125.239(gd1)--hk1--co(alphaclash.ggdev.co) 廣東代理--->香港--->加拿大
由于idc機(jī)房在加拿大,所以經(jīng)常會(huì)配些nginx多級(jí)反向代理到國(guó)內(nèi).(不做代理client就得翻墻,或者說(shuō)是丟包很嚴(yán)重.)
下面的Nginx配置我只寫80的,443的忽略,簡(jiǎn)化nginx的配置,參數(shù)也不一一列舉不然太多了.
gd1的反向代理配置:(就是一個(gè)反向代理)
cat hba.changyoufun.com.confserver{ 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的內(nèi)網(wǎng)ip): upstream hba80 { server 10.105.3.222:80; } upstream hba443 { server 10.105.3.222:443; }
hk1的反向代理配置:(也是一個(gè)nginx反向代理)
cat hba.changyoufun.com.confserver{ 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地址):
upstream hba80 { server 216.66.17.34:80; } upstream hba443 { server 216.66.17.34:443; }
co機(jī)房原先已經(jīng)存在alphaclash.ggdev.co域名的配置,只需要copy一份alphaclash.ggdev.co的nginx配置,將域名替換為hba.changyoufun.com即可.
co的兩份nginx配置:
nginx和php的web版:
cat hba.changyoufun.com.confserver{ 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; }}
cat alphaclash.ggdev.co.confserver{ 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; }}
注釋:其實(shí)nginx的代理很簡(jiǎn)單,很多時(shí)候是沒(méi)想明白,既然代理alphaclash.ggdev.co,前面兩級(jí)代理配置了這個(gè)域名不就ok了?仔細(xì)想發(fā)現(xiàn)nginx代理根據(jù)ip:端口找域名,然后在location匹配到的location段再找upstream段,再根據(jù)upstream段的ip+port找下級(jí)域名,最后發(fā)現(xiàn)最后一級(jí)沒(méi)有相匹配的域名就報(bào)404了,所以最后一層也要配上相匹配的域名配置.
總結(jié)
以上所述是小編給大家介紹的Nginx多層代理配置方法,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)VEVB武林網(wǎng)網(wǎng)站的支持!
|
新聞熱點(diǎn)
疑難解答
圖片精選