---
title: "linux（CentOS,fedora）下squid3安装及反向代理配置"
author: "cjj_720"
date: "2010-08-18T23:16:04Z"
tags: []
categories: ["互联网"]
slug: "linux-centos-fedora-squid3"
draft: false
lastmod: "2010-08-18T23:16:04Z"
id: 740610
url: "https://cprime.iteye.com/blog/740610"
---

下载源码包并解压
./configure --prefix=/usr/local/squid --enable-gnuregex --enable-async-io=20 --enable-icmp --enable-linux-netfilter --enable-kill-parent-hack --enable-snmp --disable-ident-lookups --enable-cache-digests --enable-arp-acl --enable-err-language="Simplify_Chinese"--enable-default-err-languages="Simplify_Chinese"  --enable-poll --enable-linux-netfilter --enable-underscore
make
make install
mkdir /usr/local/squid/cache
chown -R nobody:nobody /var/squid/cache
chmod 777 /var/squid/cache -R
/usr/local/squid/sbin/squid -z
配置反向代理
打开etc/squid.conf文件

**acl**
在文件里找到TAG: acl的位置，在其后加上我们的设置：

acl sites dstdomain .foo.com
acl sites dstdomain .bar.com

**http_access**

在文件里找到TAG: http_access的位置，其后有一行注释：

# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS

我们就把自定义的规则放在这行的下面：

http_access allow sites

http_access的位置是很重要的，在下面有如下设置：

# And finally deny all other access to this proxy
http_access deny all

它会拒绝所有剩下的访问。

**http_port**

在文件里找到TAG: http_port的位置，在其后加上我们的设置：

http_port 80 defaultsite=缺省站点 vhost

一般来说，vhost就足够了，不过加上defaultsite还是有好处的，毕竟，有的HTTP1.0客户端不发送Host头，在这种情况下系统有一个缺省值总比没有强。

**cache_peer**

在文件里找到TAG: cache_peer的位置，在其后加上我们的设置：

cache_peer x.x.x.x parent 80 0 no-query originserver name=foo
cache_peer y.y.y.y parent 80 0 no-query originserver name=bar
80为web服务器访问端口

**cache_peer_domain**

在文件里找到TAG: cache_peer_domain的位置，在其后加上我们的设置：

cache_peer_domain foo www.foo.com
cache_peer_domain bar www.bar.com

**cache_peer_access**

在文件里找到TAG: cache_peer_access的位置，在其后加上我们的设置：

cache_peer_access foo allow sites

启动sbin/squid -s
如果不想查找dns，则增加-D选项