您好,登錄后才能下訂單哦!
本篇內(nèi)容介紹了“怎么配置HTTP/HTTPS自動(dòng)加密上網(wǎng)”的有關(guān)知識(shí),在實(shí)際案例的操作過(guò)程中,不少人都會(huì)遇到這樣的困境,接下來(lái)就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
涉及到的軟件
此方案優(yōu)缺點(diǎn)
優(yōu)點(diǎn):
無(wú)需手動(dòng)設(shè)置任何代理,就能夠自動(dòng)加密代理特定網(wǎng)站的HTTP或HTTPS協(xié)議
相對(duì)于我們常用的ssh隧道,ssh隧道是單路,而此方案是支持多并發(fā)連接,可以極大加速網(wǎng)站訪問(wèn)。
缺點(diǎn):
對(duì)于代理HTTPS協(xié)議,需要發(fā)起HTTPS連接的客戶端,比如瀏覽器支持TLS的SNI擴(kuò)展。好消息是目前瀏覽器幾乎都支持此擴(kuò)展,但對(duì)于一些非瀏覽器的客戶端,不支持SNI擴(kuò)展。我們只能設(shè)置正向代理來(lái)解決此問(wèn)題。
原理介紹:
1、首先我們需要準(zhǔn)備三臺(tái)服務(wù)器,一臺(tái)是內(nèi)網(wǎng)DNS服務(wù)器(安裝bind),一臺(tái)是內(nèi)網(wǎng)代理服務(wù)器(安裝stunnel),另一臺(tái)國(guó)外服務(wù)器(安裝stunnel,sniproxy)。
2、我們還需要設(shè)置DNS為內(nèi)網(wǎng)的DNS,并在內(nèi)網(wǎng)bind dns設(shè)置谷歌域名解析的IP為內(nèi)網(wǎng)代理服務(wù)器
3、當(dāng)我們?cè)L問(wèn)谷歌網(wǎng)站時(shí),首先會(huì)向內(nèi)網(wǎng)DNS服務(wù)器發(fā)送DNS A記錄查詢,此時(shí)內(nèi)網(wǎng)DNS服務(wù)器會(huì)返回內(nèi)網(wǎng)代理服務(wù)器的IP。
4、瀏覽器得到谷歌域名的解析IP后(即內(nèi)網(wǎng)代理服務(wù)器的IP),會(huì)向內(nèi)網(wǎng)代理服務(wù)器發(fā)送HTTP或HTTPS請(qǐng)求。
5、此時(shí)內(nèi)網(wǎng)代理服務(wù)器(即stunnel),會(huì)接收到請(qǐng)求,經(jīng)過(guò)加密,把請(qǐng)求轉(zhuǎn)發(fā)到國(guó)外服務(wù)器(stunnel)的指定端口上。
6、國(guó)外服務(wù)器(stunnel)接收到來(lái)自國(guó)內(nèi)服務(wù)器(stunnel)的加密數(shù)據(jù)后,經(jīng)過(guò)解密,把請(qǐng)求轉(zhuǎn)發(fā)到sniproxy。
7、sniproxy再根據(jù)HTTP Host請(qǐng)求頭或者HTTPS sni擴(kuò)展的域名解析出谷歌服務(wù)器的IP,并把請(qǐng)求轉(zhuǎn)發(fā)給谷歌服務(wù)器。
8、谷歌服務(wù)器收到來(lái)自sniproxy發(fā)送的請(qǐng)求后,馬上返回網(wǎng)頁(yè)內(nèi)容給sniproxy,sniproxy再原路返回?cái)?shù)據(jù)給瀏覽器。
由于時(shí)間有限,我們僅在Ubuntu server 12.04演示安裝。
系統(tǒng):Ubuntu server 12.04
內(nèi)網(wǎng)DNS IP: 10.96.153.201(主),10.96.153.204(從)
內(nèi)網(wǎng)代理服務(wù)器: 10.96.153.204
國(guó)外服務(wù)器IP: 1.2.3.4
1、在主DNS和從DNS安裝bind,即10.96.153.201(主),10.96.153.204(從)。
wget http://www.isc.org/downloads/file/bind-9-10-0b1-2/?version=tar.gz -O bind-9-10-0b1-2.tar.gz tar xzf bind-9-10-0b1-2.tar.gz cd bind-9-10-0b1-2 ./configure --prefix=/usr/local/bind make && make install
2、配置主DNS服務(wù)器(10.96.153.201)
2.1、生成/usr/local/bind/etc/rndc.key密鑰文件
/usr/local/bind/sbin/rndc-confgen -a -k rndckey -c /usr/local/bind/etc/rndc.key
2.2、編輯/usr/local/bind/etc/named.conf,寫入如何內(nèi)容:
include "/usr/local/bind/etc/rndc.key"; controls { inet 127.0.0.1 port 953 allow { 127.0.0.1; } keys { "rndckey"; }; }; logging { channel default_syslog { syslog local2; severity notice; }; channel audit_log { file "/var/log/bind.log"; severity notice; print-time yes; }; category default { default_syslog; }; category general { default_syslog; }; category security { audit_log; default_syslog; }; category config { default_syslog; }; category resolver { audit_log; }; category xfer-in { audit_log; }; category xfer-out { audit_log; }; category notify { audit_log; }; category client { audit_log; }; category network { audit_log; }; category update { audit_log; }; category queries { audit_log; }; category lame-servers { audit_log; }; }; options { directory "/usr/local/bind/etc"; pid-file "/usr/local/bind/var/run/bind.pid"; transfer-format many-answers; interface-interval 0; forward only; forwarders { 202.96.128.166;202.96.134.133; }; allow-query {any;}; }; zone "google.com" { type master; file "google.com.zone"; allow-transfer { 10.96.153.204; }; };
在這個(gè)named.conf文件中,我們只需要關(guān)心如下內(nèi)容:
對(duì)于options{}區(qū)域,202.96.128.166和202.96.134.133這兩個(gè)是ISP提供的本地DNS,需要修改為自己所在ISP的本地DNS。
對(duì)于zone “google.com”{}區(qū)域,這里定義了google.com域名的區(qū)域文件google.com.zone,還有允許10.96.153.204(即從DNS)同步區(qū)域文件。
2.3、建立google.com.zone區(qū)域文件:
$TTL 3600 @ IN SOA ns1.google.com. hostmaster.google.com. ( 2014072015 ; Serial 3600 ; Refresh 900 ; Retry 3600000 ; Expire 3600 ) ; Minimum @ IN NS ns1.google.com. @ IN NS ns2.google.com. ns1 IN A 10.96.153.201 ns2 IN A 10.96.153.204 @ IN A 10.96.153.204 * IN A 10.96.153.204
對(duì)于這個(gè)區(qū)域文件:
ns1 IN A 10.96.153.201 指向第一個(gè)dns服務(wù)器,即主DNS。
ns2 IN A 10.96.153.204 指向第二個(gè)dns服務(wù)器,即從DNS。
@ IN A 10.96.153.204和* IN A 10.96.153.204指向內(nèi)網(wǎng)的代理服務(wù)器(stunnel)。我們只需要修改這三個(gè)地方就好了。
3、配置從DNS服務(wù)器(10.96.153.204)
編輯named.conf,寫入如下內(nèi)容
logging { channel default_syslog { syslog local2; severity notice; }; channel audit_log { file "/var/log/bind.log"; severity notice; print-time yes; }; category default { default_syslog; }; category general { default_syslog; }; category security { audit_log; default_syslog; }; category config { default_syslog; }; category resolver { audit_log; }; category xfer-in { audit_log; }; category xfer-out { audit_log; }; category notify { audit_log; }; category client { audit_log; }; category network { audit_log; }; category update { audit_log; }; category queries { audit_log; }; category lame-servers { audit_log; }; }; options { directory "/usr/local/bind/etc"; pid-file "/usr/local/bind/var/run/bind.pid"; transfer-format many-answers; interface-interval 0; forward only; forwarders { 202.96.128.166;202.96.134.133; }; allow-query {any;}; }; zone "google.com" { type slave; file "google.com.zone"; masters { 10.96.153.201; }; };
配置從DNS就簡(jiǎn)單得多,只需要寫入如上內(nèi)容到named.conf文件。同樣的,options{}中202.96.128.166和202.96.134.133這兩個(gè)是當(dāng)?shù)豂SP本地dns。zone “google.com”{}中10.96.153.201指明主DNS服務(wù)器IP。
4、啟動(dòng)bind dns服務(wù)器
/usr/local/bind/sbin/named
1、在內(nèi)網(wǎng)代理服務(wù)器和國(guó)外主機(jī)安裝stunnel
apt-get install stunnel4
2、內(nèi)網(wǎng)代理服務(wù)器stunnel配置
編輯/etc/default/stunnel4,設(shè)置ENABLED=1。
client = yes pid = /etc/stunnel/stunnel.pid [http] accept = 80 connect = 1.2.3.4:8082 [https] accept = 443 connect = 1.2.3.4:4433
此配置文件表示,監(jiān)聽(tīng)了80端口,并把此端口流量轉(zhuǎn)發(fā)到1.2.3.4:8082,監(jiān)聽(tīng)了443端口,并把此端口流量轉(zhuǎn)發(fā)到1.2.3.4:4433
3、國(guó)外服務(wù)器stunnel配置
3.1、生成ssl證書stunnel.pem文件
openssl genrsa -out key.pem 2048 openssl req -new -x509 -key key.pem -out cert.pem -days 1095 cat key.pem cert.pem >> /etc/stunnel/stunnel.pem
3.2、編輯/etc/stunnel/stunnel.conf文件
client = no [http] accept = 1.2.3.4:8082 connect = 127.0.0.1:8082 cert = /etc/stunnel/stunnel.pem [https] accept = 1.2.3.4:4433 connect = 127.0.0.1:4433 cert = /etc/stunnel/stunnel.pem
此配置文件表示,監(jiān)聽(tīng)了1.2.3.4:8082,并轉(zhuǎn)發(fā)此地址流量到127.0.0.1:8082,監(jiān)聽(tīng)了1.2.3.4:4433,并轉(zhuǎn)發(fā)給地址流量到127.0.0.1:4433。
3.3、編輯/etc/default/stunnel4,設(shè)置ENABLED=1。
4、啟動(dòng)stunnel
service stunnel4 start
sniproxy項(xiàng)目地址:https://github.com/dlundquist/sniproxy
1、安裝sniproxy
同樣只演示在ubuntu server 12.04安裝。
1.1、安裝UDNS
mkdir udns_packaging cd udns_packaging wget http://archive.ubuntu.com/ubuntu/pool/universe/u/udns/udns_0.4-1.dsc wget http://archive.ubuntu.com/ubuntu/pool/universe/u/udns/udns_0.4.orig.tar.gz wget http://archive.ubuntu.com/ubuntu/pool/universe/u/udns/udns_0.4-1.debian.tar.gz tar xfz udns_0.4.orig.tar.gz cd udns-0.4/ tar xfz ../udns_0.4-1.debian.tar.gz dpkg-buildpackage cd .. dpkg -i *.deb
1.2、安裝sniproxy
apt-get install autotools-dev cdbs debhelper dh-autoreconf dpkg-dev gettext libev-dev libpcre3-dev libudns-dev pkg-config wget https://github.com/dlundquist/sniproxy/archive/master.zip unzip master.zip cd sniproxy-master/ dpkg-buildpackage cd .. dpkg -i *.deb
2、配置sniproxy
/etc/sniproxy.conf內(nèi)容如下:
user daemon pidfile /var/run/sniproxy.pid error_log { syslog deamon priority notice } listen 127.0.0.1:8082 { proto http table http_hosts } table http_hosts { .* *:80 } listen 127.0.0.1:4433 { proto tls table https_hosts } table https_hosts { .* *:443 }
此配置文件表示,監(jiān)聽(tīng)了127.0.0.1:8082地址,并解析http協(xié)議中的Host請(qǐng)求頭為IP,然后轉(zhuǎn)發(fā)請(qǐng)求到此IP;監(jiān)聽(tīng)了127.0.0.1:4433地址,并解析TLS中SNI擴(kuò)展中的域名為IP,并轉(zhuǎn)發(fā)請(qǐng)求到此IP。
3、啟動(dòng)sniproxy
sniproxy
“怎么配置HTTP/HTTPS自動(dòng)加密上網(wǎng)”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。