linux squid 代理服务配置

/*

1:squid 普通代理

a:条件

squid 服务器用于两块网卡

eth0 192.168.1.1

eth1 200.168.10.1

局域网pc

eth0 192.168.1.2

b:配置

squid 服务器安装squid软件后

在 /etc/squid/squid.conf 写入

http_port 192.168.1.1:3128 -->代理服务器的ip地址以及端口

visiable_hostname 192.168.1.1 --> 代理服务器名称必须写

cache_dir ufs /var/spool/squid/ 10 16 256 --> squid 缓存目录

acl acc_net 192.168.1.0/24 ---> 允许的ip列表

acl all 0.0.0.0/allow ---> 不允许的ip列表

http_access allow acc_net ---> 设置允许

http_access deny allow ---> 设置不允许

c:在局域网内浏览器代理填写squid 服务器的ip以及端口号

代理完成



d:注:squid iptables 尽可能关闭



2: squid 透明代理

a:条件

squid 服务器用于两块网卡

eth0 192.168.1.1

eth1 200.168.10.1

局域网pc

eth0 192.168.1.2

设置网关: 192.168.10.1

b:配置

squid 服务器安装squid软件后

在 /etc/squid/squid.conf 写入

http_port 192.168.1.1:3128 transparent -->代理服务器的ip地址以及端口

visiable_hostname 192.168.1.1 --> 代理服务器名称必须写

cache_dir ufs /var/spool/squid/ 10 16 256 --> squid 缓存目录

acl acc_net 192.168.1.0/24 ---> 允许的ip列表

acl all 0.0.0.0/allow ---> 不允许的ip列表

http_access allow acc_net ---> 设置允许

http_access deny allow ---> 设置不允许

c:设置iptable防火墙(局域网内的数据包发到网关后,squid服务器在路由前将数据包丢到squid代理服务器3128端口处理)

iptables -t nat -I PREROUTING -i eth0 -s 192.168.10.0/24 -p tcp --dport 80 -j REDIRECT --to 3128



3: squid 反向代理

a:条件

squid 服务器用于两块网卡

eth0 200.168.10.1

eth1 192.168.1.1

外网pc

eth0 200.168.10.2

b:配置

vim /etc/squid/squid.conf 

http_port 200.168.10.1:3128 vhost

visiable_hostname 200.168.10.1

acl 0.0.0.0/all

http_access allow all

cahe_peer 192.168.10.2 parent 80 0 originserver weight 1 man-conn=30



c:完成



3.0:虚拟主机的代理

a:在真实服务器上配置虚拟主机

vim /etc/httpd/conf/httpd_conf

NameVirtualHost *:80

<VirtualHost *:80>

DocumentRoot /var/www/html/vhost1/

ServerName www.vhost0.com

<Directory "/var/www/html/vhost1">

Options indexs

AllowOverride None

Order deny,allow

allow from all

</Directory>

</VirtualHost>

NameVirtualHost *:80

<VirtualHost *:80>

DocumentRoot /var/www/html/vhost1/

ServerName www.vhost1.com

<Directory "/var/www/html/vhost1">

Options indexs

AllowOverride None

Order deny,allow

allow from all

</Directory>

</VirtualHost>

b: 在squid服务器中配置

vim /etc/squid/squid.conf

http_port 200.168.10.1:80 vhost

http_hostName 200.168.10.1

acl all 0.0.0.0/all

http_access allow all

cache_peer 192.168.10.2 parent 0 80 weight=5 max-conn=30 name=v1

cache_peer 192.168.10.2 parent 0 80 weight=5 max-conn=30 name=v2

cache_peer_domain v1 www.vhost1.com

cache_peer_domain v2 www.vhost2.com

cache_peer_access v1 allow all

cache_peer_access v2 allow all



squid -k reconfig



ok!!

 

你可能感兴趣的:(linux)