CentOS7.2搭建代理服务器
来源:互联网 发布:vue引入第三方js 编辑:程序博客网 时间:2024/05/17 06:55
CentOS7.2搭建代理服务器
有时候内网很多机器都不能上外网,只能开放几个特定ip访问外网, 那么可以在这个可以上外网的机器上面搭建代理服务器,其他机器配置好代理就能上网了。
不管是测试用途还是自己使用,squid都是一个很不错的代理工具。支持正向代理、反向代理、还有透明代理。 本篇演示搭建了一个简单的squid的正向代理,同时支持认证,随便记记笔记。
安装
12
yum install squid -yyum install httpd-tools -y
生成密码文件
12345
mkdir /etc/squid3/# xiongneng 是用户名htpasswd -cd /etc/squid3/passwords xiongneng# 提示输入密码,在这里我设的密码为 123456# 注意密码不要超过8位
测试密码文件
1234567
/usr/lib64/squid/basic_ncsa_auth /etc/squid3/passwords# 输入 用户名 密码xiongneng 123456# 提示OK说明成功,ERR是有问题,请检查一下之前步骤OK# 测试完成,crtl + c 打断
配置
123456789101112
vim /etc/squid/squid.conf# 在最后添加auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid3/passwordsauth_param basic realm proxyacl authenticated proxy_auth REQUIREDhttp_access allow authenticated# 这里是端口号,可以按需修改# http_port 3128 这样写会同时监听ipv6和ipv4的端口,推荐适应下面的配置方法。http_port 0.0.0.0:3128
权限控制
squid的权限控制很灵活,具体配置方法可以参考 官方文档, 或者 Squid中文权威指南, 具体工作原理有点像iptables,用规则去卡控流量。默认的配置只能允许内网用户访问,如果有更多需求,你还可以指定很多规则!
下面是我的配置实例:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
# Example rule allowing access from your local networks.# Adapt to list your (internal) IP networks from where browsing# should be allowedacl all src all# RFC1918 possible internal network 全部开放acl localnet src 10.0.0.0/8# RFC1918 possible internal networkacl localnet src 172.16.0.0/12# RFC1918 possible internal networkacl localnet src 192.168.0.0/16# RFC1918 possible internal networkacl localnet src fc00::/7 # RFC 4193 local private network rangeacl localnet src fe80::/10 # RFC 4291 link-local (directly plugged) machinesacl SSL_ports port 443acl Safe_ports port 80# httpacl Safe_ports port 21# ftpacl Safe_ports port 443# httpsacl Safe_ports port 70# gopheracl Safe_ports port 210# waisacl Safe_ports port 1025-65535# unregistered portsacl Safe_ports port 280# http-mgmtacl Safe_ports port 488# gss-httpacl Safe_ports port 591# filemakeracl Safe_ports port 777# multiling httpacl CONNECT method CONNECT## Recommended minimum Access Permission configuration:## Deny requests to certain unsafe portshttp_access deny !Safe_ports# Deny CONNECT to other than secure SSL portshttp_access deny CONNECT !SSL_ports# Only allow cachemgr access from localhosthttp_access allow localhost managerhttp_access deny manager# We strongly recommend the following be uncommented to protect innocent# web applications running on the proxy server who think the only# one who can access services on "localhost" is a local user#http_access deny to_localhost## INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS## Example rule allowing access from your local networks.# Adapt localnet in the ACL section to list your (internal) IP networks# from where browsing should be allowedhttp_access allow localnethttp_access allow localhost# And finally deny all other access to this proxyhttp_access deny all
日志
squid的日志默认是打开的,位于目录/var/log/squid/
,当然这个地址还有日志的格式都是可以完全自定义的
12345678
[root@controller161 ~]# ll /var/log/squid/total 496-rw-r----- 1 squid squid 355208 May 6 12:17 access.log-rw-r----- 1 squid squid 1846 Jul 10 2016 access.log-20160710.gz-rw-r----- 1 squid squid 3710 Jul 15 2016 access.log-20160718.gz-rw-r----- 1 squid squid 125341 May 4 15:19 cache.log-rw-r----- 1 squid squid 1325 Jul 9 2016 cache.log-20160710.gz-rw-r----- 1 squid squid 1110 Jul 14 2016 cache.log-20160718.gz
启动服务
12345678
# 开启启动systemctl enable squid.service# 启动systemctl start squid.service# 停止systemctl stop squid.service# 重启systemctl restart squid.service
代理服务器设置
在其他CentOS机器上面配置各种代理方法
全局代理
vim /etc/profile
,在最后加入
12
export http_proxy="http://username:password@proxy_ip:port"export https_proxy="http://username:password@proxy_ip:port"
yum代理设置
编辑/etc/yum.conf
,在最后加入
12
# Proxyproxy=http://username:password@proxy_ip:port/
wget的代理设置
编辑/etc/wgetrc
,在最后加入
1234
# Proxyhttp_proxy=http://username:password@proxy_ip:port/https_proxy=http://username:password@proxy_ip:port/ftp_proxy=http://username:password@proxy_ip:port/
curl的代理设置
在~/.bashrc
里面增加一个别名:
1
alias curl="curl -x http://username:password@proxy_ip:port"
另外一种方法是编辑~/.curlrc
文件 (没有就创建一个):
1
proxy = http://username:password@proxy_ip:port
阅读全文
0 0
- CentOS7.2搭建代理服务器
- Centos7搭建代理服务器Shadowsocks
- Centos7搭建代理服务器Shadowsocks
- CentOS7下搭建nginx反向代理服务器 二级域名访问
- centos7.2环境搭建
- 2-Centos7-Seafile搭建
- centOs7.2 lamp搭建
- CentOS7下搭建nginx反向代理服务器使得外网可以二级域名访问内网应用
- 转 Centos7下使用Squid快速搭建带认证的HTTP代理服务器
- Centos7下使用Squid快速搭建带认证的HTTP代理服务器
- 使用apache搭建代理服务器
- Nginx搭建反向代理服务器
- weblogic集群搭建、代理服务器
- 代理服务器的搭建
- Apache搭建代理服务器
- nginx代理服务器的搭建
- 搭建shadowsocks的代理服务器
- devpi搭建缓存代理服务器
- pytorch学习_2
- 翻译:iOS视图控制器编程指南(十)——自定义过渡动画(Customizing the Transition Animations)
- 迈出从3K到1W的重要一步——掌握设计模式
- 2017年度开源贡献榜 国内阿里排第一
- HDU 5927 (最近公共祖先)(bfs+树)
- CentOS7.2搭建代理服务器
- 微信三大平台
- “安防+”时代 物联网开辟新机遇
- 大小端的判断 十进制itoa实现
- C#选择文件、选择文件夹、打开文件(或者文件夹)
- Java
- 如何给变量命名-彻底告别变量命名的苦恼
- 20171031
- 常用Linux命令集合(随用随更新)