最近項目引入反向 Proxy和緩衝,熟悉了一下Squid、Apache、Valish、Nginx,根據項目實際進行選擇,客觀來說,採用Linux系統部署最好,也沒有什麼難度,但實際情況必須採用Windows系統(本著方案要結合現實的原則,研究要以Windows平台為主)。
一 Squid 配置:
在squid.conf設定檔末尾加上如下內容:
#show squid namevisible_hostname tg.squid-cache.jjtg.com#cache_managercache_mgr xxx@abc.com #郵箱地址#DNS查詢dns_testnames 192.168.45.45#squid監聽http_port 7575 accel vhost vport#後端網站cache_peer 192.168.45.45 parent 7574 0 no-query originserver connect-timeout=180#chache_memorycache_mem 800 MBcache_swap_low 90cache_swap_high 95#cache_dir::注意路徑cache_dir ufs E:/var/squid/tg/cache 100000 16 256#cache_logs::注意路徑cache_log E:/var/squid/tg/logs/cache.loglogformat squid %ts.%03tu %6tr %>a %Ss/%03Hs %<st %rm %ru %un %Sh/%<A %mtaccess_log E:/var/squid/tg/logs/access.log squidcache_store_log E:/var/squid/tg/logs/store.log#cache_log none#access_log none#cache_store_log nonepid_filename E:/var/squid/tg/logs/squid.pid#cache runnercache_effective_user squidcache_effective_group squids#隱藏不是必須的header#2.x用header_access,3.x用reply_header_accessheader_access ETag deny allheader_access Vary deny allheader_access Accept-Ranges deny allheader_access X-AspNet-Version deny allheader_access X-Powered-By deny all#禁止緩衝的檔案 #hierarchy_stoplist -i \.aspx \.asmx \.ashxacl NoneCache urlpath_regex -i \.aspx \.asmx \.ashxno_cache deny NoneCache #只允許本地PUGREacl AdminBoxes src 127.0.0.1 192.168.0.0/16acl Purge method PURGEhttp_access allow AdminBoxes Purgehttp_access deny Purge #squid ACL rules#acl all src allhttp_access allow all#http_access deny all
二 Apache配置
在httpd.conf設定檔修改:
#增加監聽連接埠: Listen 7570 Listen 7574 #修改ServerName:ServerName 192.168.45.45:7570#使用者自訂添加代理 #開啟mod_proxy,mod_proxy_connect,mod_proxy_http #代理攔截 <VirtualHost 192.168.45.45:7574> ServerName 192.168.45.45:7574 ProxyPass / http://192.168.45.45:7573/ ProxyPassReverse / http://192.168.45.45:7573/ </VirtualHost> #使用者自訂配置靜態檔案的Expires: <IfModule mod_headers.c> #使用者自訂去掉某些不必要的Header資訊 #header unset Etag #開啟mod_expires ExpiresActive On ExpiresByType image/x-icon "access plus 1 months" ExpiresByType application/x-javascript "access plus 1 weeks" ExpiresByType text/css "access plus 1 weeks" ExpiresByType image/gif "access plus 1 months" ExpiresByType image/png "access plus 1 months" ExpiresByType image/jpeg "access plus 1 months" ExpiresByType application/x-shockwave-flash "access plus 1 months" ExpiresByType video/x-flv "access plus 1 months" ExpiresByType application/pdf "access plus 1 months" #ExpiresByType text/html "access plus 1 weeks" <FilesMatch "^(.*)\.(aspx|asmx|ashx)($|.*)"> Header unset Cache-Control Header unset Expires Header set Cache-Control "no-cache,no-store" Header set Pragma "no-cache" </FilesMatch> </IfModule>
三 修改Apache串連數:
1.修改httpd.conf檔案
Include conf/extra/httpd-mpm.conf #去掉該行的注釋,引用httpd-mpm.conf檔案
2.修改/extra/httpd-mpm.conf
#linux下:#原:<IfModule mpm_prefork_module>StartServers 5MinSpareServers 5MaxSpareServers 10MaxClients 150MaxRequestPerClild 0</IfModule>#改為:<IfModule mpm_prefork_module>StartServers 5MinSpareServers 5MaxSpareServers 10ServerLimit 1500MaxClients 1000MaxRequestsPerChild 0</IfModule>#windows:#原:<IfModule mpm_winnt_module> ThreadsPerChild 150 MaxRequestsPerChild 0</IfModule>#改為:<IfModule mpm_winnt_module> ThreadsPerChild 500 MaxRequestsPerChild 5000</IfModule>
4.改後,不能用restart重啟,而要用stop停止,star啟動