{"id":343,"date":"2011-04-14T16:38:54","date_gmt":"2011-04-14T16:38:54","guid":{"rendered":""},"modified":"2013-02-07T12:10:28","modified_gmt":"2013-02-07T04:10:28","slug":"centos-squid-server-%e5%ae%89%e8%a3%85%e9%85%8d%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/ybzx.vip\/wp\/?p=343","title":{"rendered":"CentOS Squid Server \u5b89\u88c5\u914d\u7f6e"},"content":{"rendered":"<p>Squid\u662f\u4e00\u4e2a\u7f13\u5b58internet\u6570\u636e\u7684\u4e00\u4e2a\u8f6f\u4ef6\uff0c\u5b83\u63a5\u6536\u7528\u6237\u7684\u4e0b\u8f7d\u7533\u8bf7\uff0c\u5e76\u81ea\u52a8\u5904\u7406\u6240\u4e0b\u8f7d\u7684\u6570\u636e\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u5f53\u4e00\u4e2a\u7528\u6237\u8c61\u8981\u4e0b\u8f7d\u4e00\u4e2a\u4e3b\u9875\u65f6\uff0c\u5b83\u5411 Squid\u53d1\u51fa\u4e00\u4e2a\u7533\u8bf7\uff0c\u8981Squid\u66ff\u5b83\u4e0b\u8f7d\uff0c\u7136\u540eSquid \u8fde\u63a5\u6240\u7533\u8bf7\u7f51\u7ad9\u5e76\u8bf7\u6c42\u8be5\u4e3b\u9875\uff0c\u63a5\u7740\u628a\u8be5\u4e3b\u9875\u4f20\u7ed9\u7528\u6237\u540c\u65f6\u4fdd\u7559\u4e00\u4e2a\u5907\u4efd\uff0c\u5f53\u522b\u7684\u7528\u6237\u7533\u8bf7\u540c\u6837\u7684\u9875\u9762\u65f6\uff0cSquid\u628a\u4fdd\u5b58\u7684\u5907\u4efd\u7acb\u5373\u4f20\u7ed9\u7528\u6237\uff0c\u4f7f\u7528\u6237\u89c9\u5f97\u901f\u5ea6\u76f8\u5f53\u5feb\u3002<!--more--><\/p>\n<p>\u5b89\u88c5 <br \/>yum install squid<\/p>\n<p>\u4fee\u6539\u914d\u7f6e\u6587\u4ef6 \/etc\/squid\/squid.conf<br \/>\uff08\u5982\u679c\u8be5\u6587\u4ef6\u914d\u7f6e\u574f\u6389\u4e86\uff0c\u6709 squid.conf.default \u53ef\u4ee5\u5907\u7528\uff0c\u4e24\u4e2a\u6587\u4ef6\u5728\u521a\u5b89\u88c5\u540e\u662f\u4e00\u6a21\u4e00\u6837\u7684\uff09<\/p>\n<p># squid \u7aef\u53e3\uff0c\u9ed8\u8ba4\u662f3128<br \/>http_port 3128<\/p>\n<p># \u6307\u5b9a\u786c\u76d8\u7f13\u51b2\u533a\u7684\u5927\u5c0f<br \/># ufs: \u7f13\u5b58\u7c7b\u578b<br \/># \/var\/spool\/squid\uff1a\u7f13\u5b58\u76ee\u5f55<br \/># 300\uff1a\u7f13\u5b58\u5927\u5c0f\uff08Mbytes\uff09<br \/># \u5141\u8bb8\u5728\u201c\/tmp\u201d\u4e0b\u521b\u5efa\u7684\u7b2c\u4e00\u7ea7\u5b50\u76ee\u5f55\u6570\u4e3a16\uff0c\u6bcf\u4e2a\u7b2c\u4e00\u7ea7\u5b50\u76ee\u5f55\u4e0b\u53ef\u4ee5\u521b\u5efa\u7684\u7b2c\u4e8c\u7ea7\u5b50\u76ee\u5f55\u6570\u91cf\u4e3a256<br \/>cache_dir ufs \/var\/spool\/squid 300 16 256<\/p>\n<p># \u81ea\u5b9a\u4e49\u67d0\u4e2aIP\u6216\u8005\u67d0\u7f51\u6bb5\uff0c\u4f7f\u7528 http_access \u9009\u9879\u5141\u8bb8\u8be5\u5217\u8868<br \/>acl our_networks src 11.11.11.11\/255.255.255.255<br \/>acl our_networks src 12.12.12.12\/29<br \/>http_access allow our_networks<\/p>\n<p># \u670d\u52a1\u5668\u7684\u4e3b\u673a\u540d\uff0c\u53ef\u968f\u4fbf\u5b9a\u4e49<br \/>visible_hostname 221_170<\/p>\n<p># \u5173\u95ed\u6b64\u9879\u5c06\u5728\u8bbf\u95ee\u7f51\u7ad9\u65f6\u663e\u793a\u7684IP\u662funknown\uff0c\u5982\u679c\u6253\u5f00\u5219\u663e\u793a\u7684\u662f\u4f60client\u7684\u5185\u7f51IP<br \/>forwarded_for off<\/p>\n<p># \u9632\u6b62\u77e5\u9053\u5ba2\u6237\u7684\u5185\u90e8 ip<br \/>header_access Via deny all<\/p>\n<p># \u9632\u6b62\u77e5\u9053\u4ee3\u7406\u670d\u52a1\u5668\u7684\u670d\u52a1\u5668\u540d\u4ee5\u53ca\u7aef\u53e3<br \/>header_access X-Forwarded-For deny all<\/p>\n<p>\u542f\u52a8 squid<br \/>service squid start<\/p>\n<p>squid \u7684 log\uff1a\/var\/log\/squid\/<br \/>access.log cache.log squid.out store.log<\/p>\n<p>\u7ed9\u51fa\u4e00\u4e9b header\uff0c\u53ef\u4ee5\u5c4f\u853d\u5b83\u4eec<\/p>\n<p>Accept&nbsp;&nbsp;HTTP_ACCEPT<br \/>Accept-Charset&nbsp;&nbsp;HTTP_ACCEPT-CHARSET<br \/>Accept-Encoding&nbsp;&nbsp;HTTP_ACCEPT-ENCODING<br \/>Accept-Language&nbsp;&nbsp;HTTP_ACCEPT-LANGUAGE<br \/>Accept-Ranges&nbsp;&nbsp;HTTP_ACCEPT-RANGES<br \/>Age&nbsp;&nbsp;HTTP_AGE<br \/>Allow&nbsp;&nbsp;HTTP_ALLOW<br \/>Authorization&nbsp;&nbsp;HTTP_AUTHORIZATION<br \/>Cache-Control&nbsp;&nbsp;HTTP_CACHE-CONTROL<br \/>Connection&nbsp;&nbsp;HTTP_CONNECTION<br \/>Content-Base&nbsp;&nbsp;HTTP_CONTENT-BASE<br \/>Content-Disposition&nbsp;&nbsp;HTTP_CONTENT-DISPOSITION<br \/>Content-Encoding&nbsp;&nbsp;HTTP_CONTENT-ENCODING<br \/>Content-Language&nbsp;&nbsp;HTTP_CONTENT-LANGUAGE<br \/>Content-Length&nbsp;&nbsp;HTTP_CONTENT-LENGTH<br \/>Content-Location&nbsp;&nbsp;HTTP_CONTENT-LOCATION<br \/>Content-MD5&nbsp;&nbsp;HTTP_CONTENT-MD5<br \/>Content-Range&nbsp;&nbsp;HTTP_CONTENT-RANGE<br \/>Content-Type&nbsp;&nbsp;HTTP_CONTENT-TYPE<br \/>Cookie&nbsp;&nbsp;HTTP_COOKIE<br \/>Date&nbsp;&nbsp;HTTP_DATE<br \/>ETag&nbsp;&nbsp;HTTP_ETAG<br \/>Expires&nbsp;&nbsp;HTTP_EXPIRES<br \/>From&nbsp;&nbsp;HTTP_FROM<br \/>Host&nbsp;&nbsp;HTTP_HOST<br \/>If-Match&nbsp;&nbsp;HTTP_IF-MATCH<br \/>If-Modified-Since&nbsp;&nbsp;HTTP_IF-MODIFIED-SINCE<br \/>If-None-Match&nbsp;&nbsp;HTTP_IF-NONE-MATCH<br \/>If-Range&nbsp;&nbsp;HTTP_IF-RANGE<br \/>Last-Modified&nbsp;&nbsp;HTTP_LAST-MODIFIED<br \/>Link&nbsp;&nbsp;HTTP_LINK<br \/>Location&nbsp;&nbsp;HTTP_LOCATION<br \/>Max-Forwards&nbsp;&nbsp;HTTP_MAX-FORWARDS<br \/>Mime-Version&nbsp;&nbsp;HTTP_MIME-VERSION<br \/>Pragma&nbsp;&nbsp;HTTP_PRAGMA<br \/>Proxy-Authenticate&nbsp;&nbsp;HTTP_PROXY-AUTHENTICATE<br \/>Proxy-Authentication-Info&nbsp;&nbsp;HTTP_PROXY-AUTHENTICATION-INFO<br \/>Proxy-Authorization&nbsp;&nbsp;HTTP_PROXY-AUTHORIZATION<br \/>Proxy-Connection&nbsp;&nbsp;HTTP_PROXY-CONNECTION<br \/>Public&nbsp;&nbsp;HTTP_PUBLIC<br \/>Range&nbsp;&nbsp;HTTP_RANGE<br \/>Referer&nbsp;&nbsp;HTTP_REFERER<br \/>Request-Range&nbsp;&nbsp;HTTP_REQUEST-RANGE<br \/>Retry-After&nbsp;&nbsp;HTTP_RETRY-AFTER<br \/>Server&nbsp;&nbsp;HTTP_SERVER<br \/>Set-Cookie&nbsp;&nbsp;HTTP_SET-COOKIE<br \/>Title&nbsp;&nbsp;HTTP_TITLE<br \/>Transfer-Encoding&nbsp;&nbsp;HTTP_TRANSFER-ENCODING<br \/>Upgrade&nbsp;&nbsp;HTTP_UPGRADE<br \/>User-Agent&nbsp;&nbsp;HTTP_USER-AGENT<br \/>Vary&nbsp;&nbsp;HTTP_VARY<br \/>Via&nbsp;&nbsp;HTTP_VIA<br \/>Warning&nbsp;&nbsp;HTTP_WARNING<br \/>WWW-Authenticate&nbsp;&nbsp;HTTP_WWW-AUTHENTICATE<br \/>Authentication-Info&nbsp;&nbsp;HTTP_AUTHENTICATION-INFO<br \/>X-Cache&nbsp;&nbsp;HTTP_X-CACHE<br \/>X-Cache-Lookup&nbsp;&nbsp;HTTP_X-CACHE-LOOKUP<br \/>X-Forwarded-For&nbsp;&nbsp;HTTP_X-FORWARDED-FOR<br \/>X-Request-URI&nbsp;&nbsp;HTTP_X-REQUEST-URI<br \/>X-Squid-Error&nbsp;&nbsp;HTTP_X-SQUID-ERROR<br \/>Negotiate&nbsp;&nbsp;HTTP_NEGOTIATE<br \/>X-Accelerator-Vary&nbsp;&nbsp;HTTP_X-ACCELERATOR-VARY<br \/>Squid \u7528\u6237\u540d\u5bc6\u7801\u8ba4\u8bc1<br \/>\u5229\u7528 apache \u643a\u5e26\u7684\u5de5\u5177 htpasswd \u751f\u6210\u5bc6\u7801\u6587\u4ef6\u5e76\u6dfb\u52a0\u76f8\u5e94\u7684\u7528\u6237\u4fe1\u606f\uff0c\u53ef\u80fd\u9700\u8981\u5199\u5168 htpasswd \u7684\u8def\u5f84(\u5982\u679c\u8fd9\u4e2a\u670d\u52a1\u5668\u4e0a\u6709\u82e5\u5e72\u7f51\u7ad9\uff0c\u9009\u62e9\u4f7f\u752880\u7aef\u53e3\u7684\u90a3\u4e2a\u76ee\u5f55\u4e0b\u7684htpasswd)<br \/>\/usr\/bin\/htpasswd -c \/etc\/squid\/passwd testuser<br \/>\u6839\u636e\u63d0\u793a\u8f93\u5165\u5bc6\u7801\uff1a1234<br \/>\u6210\u529f\u540e\u5c06\u4f1a\u5728 \/etc\/squid\/passwd \u4e2d\u5199\u5165\uff1a<br \/>testuser:cuUEnEwyMTcGY<br \/>\u7b2c\u4e00\u5217\u8868\u660e\u7528\u6237\u540d\uff0c\u7b2c\u4e8c\u5217\u8868\u660e\u5bc6\u7801<\/p>\n<p>\u4fee\u6539 squid \u914d\u7f6e\u6587\u4ef6:<br \/># \u5b9a\u4e49\u4e86\u8ba4\u8bc1\u65b9\u5f0f\u4e3a basic\uff0c\u8ba4\u8bc1\u7a0b\u5e8f\u7684\u8def\u5f84\uff0c\u8ba4\u8bc1\u7a0b\u5ea6\u9700\u8981\u8bfb\u53d6\u7684\u5e10\u6237\u6587\u4ef6\uff08\u6ce8\u610f ncsa_auth \u548c \u4e0a\u4e2a\u6b65\u9aa4\u5efa\u7acb\u7684 passwd \u7684\u8def\u5f84\uff09<br \/>auth_param basic program \/usr\/lib\/squid\/ncsa_auth \/etc\/squid\/passwd<br \/># \u81ea\u5b9a\u4e49\u4e00\u6761\u540d\u4e3a auth_user \u7684ACL\uff0cACL\u7c7b\u578b\u4e3a proxy_auth \u901a\u8fc7\u5916\u90e8\u7a0b\u5e8f\u8fdb\u884c\u7528\u6237\u8ba4\u8bc1\u65b9\u5f0f\uff0c\u5217\u8868\u503c\u4e3aREQUIRED\uff0c\u8bf4\u660e\u63a5\u53d7\u6240\u6709\u5408\u6cd5\u7528\u6237\u7684\u8bbf\u95ee\uff0c\u7136\u540e\u4f7f\u7528 http_access \u9009\u9879\u5141\u8bb8\u8be5\u5217\u8868<br \/>acl auth_user proxy_auth REQUIRED<br \/>http_access allow auth_user<\/p>\n<p>\u4f53\u9a8c\uff1a<br \/>&#8211; \u5728\u6ca1\u6709\u5f00\u542f\u7528\u6237\u540d\u5bc6\u7801\u8ba4\u8bc1\u65f6\uff0c\u80fd\u6210\u529f\u5730\u53ea\u5141\u8bb8\u67d0\u4e9b IP \u8bbf\u95ee\u4ee3\u7406\u670d\u52a1\u5668\uff0c\u5e76\u4e14\u5c4f\u853d\u6389\u5ba2\u6237\u7aef\u7684\u4fe1\u606f\u3002<br \/>&#8211; \u5f53\u5f00\u542f\u7528\u6237\u540d\u5bc6\u7801\u8ba4\u8bc1\u65f6\uff0c\u53ea\u8981\u9a8c\u8bc1\u6210\u529f\uff0c\u65e0\u8bba IP \u662f\u4ec0\u4e48\uff0c\u90fd\u80fd\u591f\u4f7f\u7528\u4ee3\u7406\u670d\u52a1\u5668\u3002<\/p>\n<p>\u9a8c\u8bc1\u65b9\u6cd5\uff1a<br \/>\u6d4f\u89c8\u5668\u83dc\u5355 \u2013 \u5de5\u5177 \u2013 Internet\u9009\u9879 \u2013 \u8fde\u63a5 \u2013 \u5c40\u57df\u7f51\u8bbe\u7f6e \u2013 \u52fe\u9009\u201c\u4e3aLAN\u4f7f\u7528\u4ee3\u7406\u670d\u52a1\u5668\u201d\uff0c\u8f93\u5165\u4ee3\u7406\u670d\u52a1\u5668\u7684IP\u548c\u7aef\u53e3<\/p>\n<p>\u7136\u540e\u770b\u662f\u5426\u80fd\u6b63\u5e38\u6d4f\u89c8\u7f51\u9875\uff0c\u5982\u679c\u662f\u901a\u8fc7\u7528\u6237\u540d\u5bc6\u7801\u9a8c\u8bc1\u7684\uff0c\u5219\u4f1a\u8df3\u51fa\u9a8c\u8bc1\u6846\uff0c\u5982\u679c\u4e0d\u5728IP\u5141\u8bb8\u5217\u8868\u91cc\uff0c\u5219\u663e\u793a\u7684\u9875\u9762\u662f\u7981\u6b62\u8bbf\u95ee\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Squid\u662f\u4e00\u4e2a\u7f13\u5b58internet\u6570\u636e\u7684\u4e00\u4e2a\u8f6f\u4ef6\uff0c\u5b83\u63a5\u6536\u7528\u6237\u7684\u4e0b\u8f7d\u7533\u8bf7\uff0c\u5e76\u81ea\u52a8\u5904\u7406\u6240\u4e0b\u8f7d\u7684\u6570\u636e\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u5f53 &hellip; <a href=\"https:\/\/ybzx.vip\/wp\/?p=343\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">CentOS Squid Server \u5b89\u88c5\u914d\u7f6e<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[117],"tags":[79,78,90,89],"class_list":["post-343","post","type-post","status-publish","format-standard","hentry","category-network","tag-centos","tag-linux","tag-proxy","tag-squid"],"_links":{"self":[{"href":"https:\/\/ybzx.vip\/wp\/index.php?rest_route=\/wp\/v2\/posts\/343","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ybzx.vip\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ybzx.vip\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ybzx.vip\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ybzx.vip\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=343"}],"version-history":[{"count":0,"href":"https:\/\/ybzx.vip\/wp\/index.php?rest_route=\/wp\/v2\/posts\/343\/revisions"}],"wp:attachment":[{"href":"https:\/\/ybzx.vip\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=343"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ybzx.vip\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=343"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ybzx.vip\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=343"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}