Squid代理服務---反向代理

反向代理優勢

  • 經過squid反向代理能夠加速網站的訪問速度,可將不一樣的URL請求分發到後臺不一樣的web服務器上,同時互聯網用戶只能看到反向代理的服務器地址,增強了網站的訪問安全。

實驗拓撲

Squid代理服務---反向代理

服務器 操做系統 IP地址 軟件
squid反向代理 centos7.3 x86_64 192.168.144.112 squid-4.1
web1 centos7.3 x86_64 192.168.144.113 httpd
web2 centos7.3 x86_64 192.168.144.111 httpd

squid反向代理加速原理描述

  • 1)squid反向代理服務器位於本地web服務器和internet之間,客戶端請求訪問web服務器時,DNS將訪問的域名解析爲squid反向代理服務器的IP地址,客戶端將訪問squid代理服務器。
  • 2)若是squid反向代理服務器中緩存了該請求的資源,則將該請求的資源返回給客戶端,不然反向代理服務器將向後臺的web服務器請求資源,而後將應答資源返回給客戶端,同時也將該資源緩存在本地,供下一個請求者使用。

squid安裝

tar zxvf squid-4.1.tar.gz -C /opt/
cd /opt/squid-4.1linux

  • 執行安裝程序
./configure --prefix=/usr/local/squid \
--sysconfdir=/etc \
--enable-arp-acl \
--enable-linux-netfilter \
--enable-linux-tproxy \
--enable-async-io=100 \
--enable-err-language="Simplify_Chinese" \
--enable-underscore \
--enable-poll \
--enable-gnuregex

make && make install
ln -s /usr/local/squid/sbin/* /usr/local/sbin/web

useradd -M -s /sbin/nologin squidvim

chown -R squid.squid /usr/local/squid/var/centos

編輯配置文件,實現反向代理功能

vim /etc/squid.conf緩存

http_port 192.168.144.112:80 accel vhost vport   //此處squid作httpd代理,端口須要修改爲80端口,accel表示啓用加速功能
cache_peer 192.168.144.113 parent 80 0 no-query originserver round-robin max_conn=30 weight=1 name=web1   //兩個web節點服務器地址,採用輪詢rr機制,最大鏈接數30,權重爲1
cache_peer 192.168.144.111 parent 80 0 no-query originserver round-robin max_conn=30 weight=1 name=web2
cache_peer_domain web1 web2 www.yun.com   //主機域名設定

squid -k parse //檢測配置文件
squid -z //初始化
squid //啓動服務安全

  • squid服務搭建完成後,節點服務器搭建httpd服務
  • 客戶端訪問代理服務器地址192.168.144.112,也可實現訪問web頁面

Squid代理服務---反向代理

相關文章
相關標籤/搜索