squid正向代理访问外网

栏目: IT技术 · 发布时间: 5年前

内容简介:一、前言二、Squid安装三、客户端设置

目录

一、前言

二、Squid安装

三、客户端设置

四、验证

五、 Python 请求

六、写在最后

一、前言

squid正向代理访问外网

1)我们可能会碰到这样的需求,客户端Client-1需要访问Server-1,但由于各种各样的原因,不能直接通信。于是想到在中间找一台服务器做正向代理,客户端Clent1通过代理服务器与服务端Server1通信。

2)我们选择做正向代理的方式有很多,但我们这里选择Squid,可以通过性能测试等对比多个方案选出适合自己的。

二、Squid的安装

1、安装

方法一、

yum install -y gcc openssl openssl-devel
yum install squid

方法二、

wget http://www.squid-cache.org/Versions/v4/squid-4.12.tar.gz
tar -zxvf squid-4.12.tar.gz 
cd squid-4.12/
./configure --enable-ssl --with-openssl=/usr/local/openssl
make
make install

注: /usr/local/openssl指的是你的openssl目录,有的是/usr/include/openssl;如果指定不正确的话,编译会一直报错

2、修改配置文件

vim /usr/local/squid/etc/squid.conf  添加下面这一行允许所有访问,配置文件的访问策略,权限控制,缓存等后续博文更新,这里比较松的允许所有请求访问。

http_access allow all

3、启动squid

./squid

三、客户端设置

我使用google浏览器设置squid代理,设置-->高级-->打开您的计算机代理设置;squid的默认端口为3128;

squid正向代理访问外网

四、验证

通过IP即可知道是不是自己设置的代理服务器。

squid正向代理访问外网

五、Python使用代理访问

import requests

# 使用代理获取百度首页
headers = {
    "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"
}
#  定义代理的字典
proxies = {
    "https": "http://xxxxx:3128"
}
# 使用代理给服务器发送请求
response = requests.get("https://www.baidu.com", proxies=proxies, headers=headers, timeout=(3, 7))
# 获取状态
print(response.status_code)
print(response.content.decode())

六、写在最后

在平凡中坚持前行,总有一天会遇见不一样的自己。

写博客记录、思考、总结,趟过的坑不趟第二遍。

所有的文章,皆同步在公众号“运维汪”,可关注;也可加入“不扯淡,专注于技术”的QQ群:753512236

squid正向代理访问外网


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Uberland

Uberland

Alex Rosenblat / University of California Press / 2018-11-19 / GBP 21.00

Silicon Valley technology is transforming the way we work, and Uber is leading the charge. An American startup that promised to deliver entrepreneurship for the masses through its technology, Uber ins......一起来看看 《Uberland》 这本书的介绍吧!

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具