TinyProxy安装配置

来自:互联网
时间:2021-09-07
阅读:

Tinyproxy 是一个面向 POSIX 系统开发的轻量级的开源 HTTP/HTTPS 代理守护进程,其从底层开始进行设计,保证了在高速的同时体积依然很小。它很适合用于需要完整 HTTP 代理特性,但系统资源又不足以运行大型代理的场景,比如嵌入式部署。
Tineproxy 采用 GNU GPL 协议(版本2及以上)分发。

特性

Tinyproxy 的体积很小,也仅需少量系统资源。在使用 glibc 时,内存占用一般大约 2 MB,而 CPU 占用会随着连接数量线性增长(具体取决于连接速度)。因此,Tinyproxy 可用在比较老旧的计算机上,或者用在基于Linux的路由器等网络设备上,而不会对设备性能造成明显的影响。
Tinyproxy 的构建和运行仅需一个最小化的 POSIX 环境。同时,它可以用其他附加库来添加额外功能。
Tinyproxy 允许进行 HTTPS 连接的转发,而且无需通过 CONNECT 方法以任何形式修改流量内容(请参阅ConnectPort指令)。
Tinyproxy 支持被配置为一个透明代理,使客户端无需进行任何配置即可使用代理。您也可以将其用作您网站的反向代理前端。
使用 AddHeader 指令,您可以向传出的流量里添加或插入 HTTP 标头信息。
如果您要构建自定义Web代理,可以轻松地修改Tinyproxy以满足您的自定义需求。 源码结构非常简单,遵循 KISS 原则。 因此,可以把它作为基础,来实现您可能需要Web代理执行的任何操作。
Tinyproxy具有隐私功能,可让您配置哪些HTTP标头可被允许通过,哪些HTTP标头应被阻止。 这使您既可以限制从HTTP服务器向Web浏览器发送的数据(例如Cookie),也可以限制从Web浏览器到HTTP服务器发送的数据(例如版本信息)。
通过使用远程监视工具,您可以远程获知代理统计信息,从而确切了解代理的繁忙程度。
您可以配置Tinyproxy来实现 访问控制 ,从而仅允许来自特定子网或特定接口的请求,从而确保那些随机出现的、未经授权的人不能使用您的代理。
只需进行一些配置(具体而言,将Tinyproxy创建的文件设为由非root用户拥有,并让它在大于1024的端口上运行),就能让 Tinyproxy 在没有任何特殊权限的情况下运行,从而将系统受到破坏的风险降至最低。 此外,它的设计致力于防止缓冲区溢出。 代码结构的简单也确保了此类bug易于定位。

官方地址: https://tinyproxy.github.io/

日志文件默认地址:/var/log/tinyproxy/tinyproxy.log

pid文件默认地址:/var/run/tinyproxy/tinyproxy.pid

安装tinyproxy

源码版下载地址: https://github.com/tinyproxy/tinyproxy/releases

本次使用yum安装

yum -y install tinyproxy

启动

systemctl start tinyproxy
systemctl enable tinyproxy
编辑配置文件

配置文件默认地址:/etc/tinyproxy/tinyproxy.conf

#运行用户
User tinyproxy
#运行用户组
Group tinyproxy
#监听端口
Port 8888
#绑定监听IP,注释则监听全部
#Listen 192.168.0.1
#指定传出链接地址
#Bind 192.168.0.1
# 如果启用则将传出链接绑定到bind接口
#BindSame yes

#超时:连接处于不活动状态的最大秒数
Timeout 600

# ErrorFile: Defines the HTML file to send when a given HTTP error
# occurs.  You will probably need to customize the location to your
# particular install.  The usual locations to check are:
#   /usr/local/share/tinyproxy
#   /usr/share/tinyproxy
#   /etc/tinyproxy
#
#ErrorFile 404 "/usr/share/tinyproxy/404.html"
#ErrorFile 400 "/usr/share/tinyproxy/400.html"
#ErrorFile 503 "/usr/share/tinyproxy/503.html"
#ErrorFile 403 "/usr/share/tinyproxy/403.html"
#ErrorFile 408 "/usr/share/tinyproxy/408.html"

# 指定默认错误输出html文件
DefaultErrorFile "/usr/share/tinyproxy/default.html"

#
# StatHost: This configures the host name or IP address that is treated
# as the stat host: Whenever a request for this host is received,
# Tinyproxy will return an internal statistics page instead of
# forwarding the request to that host.  The default value of StatHost is
# tinyproxy.stats.
#
#StatHost "tinyproxy.stats"
 
# StatFile: The HTML file that gets sent when a request is made
# for the stathost.  If this file doesn't exist a basic page is
# hardcoded in tinyproxy.
#
StatFile "/usr/share/tinyproxy/stats.html"

# 指定日志输出文件路径
LogFile "/var/log/tinyproxy/tinyproxy.log"

# 使用syslog而不是日志文件,如正在使用LogFile指令,则不得启用该选项。两个指令互斥。
#Syslog On

# LogLevel: 
#
# Set the logging level. Allowed settings are:
#	Critical	(least verbose)
#	Error
#	Warning
#	Notice
#	Connect		(to log connections without Info's noise)
#	Info		(most verbose)
#
# The LogLevel logs from the set level and above. For example, if the
# LogLevel was set to Warning, then all log messages from Warning to
# Critical would be output, but Notice and below would be suppressed.
#
#指定日志等级
LogLevel Connect

# 指定PidFile文件路径
PidFile "/var/run/tinyproxy/tinyproxy.pid"

#告诉Tinyproxy包含X-Tinyproxy标头,该标头包含客户端的IP地址。
XTinyproxy No

#
# Upstream:
#
# 打开上游代理支持。
#
# The upstream rules allow you to selectively route upstream connections
# based on the host/domAIn of the site being accessed.
#
# For example:
#  # connection to test domain goes through testproxy
#  upstream testproxy:8008 ".test.domain.invalid"
#  upstream testproxy:8008 ".our_testbed.example.com"
#  upstream testproxy:8008 "192.168.128.0/255.255.254.0"
#
#  # no upstream proxy for internal websites and unqualified hosts
#  no upstream ".internal.example.com"
#  no upstream "www.example.com"
#  no upstream "10.0.0.0/8"
#  no upstream "192.168.0.0/255.255.254.0"
#  no upstream "."
#
#  # connection to these boxes go through their DMZ firewalls
#  upstream cust1_firewall:8008 "testbed_for_cust1"
#  upstream cust2_firewall:8008 "testbed_for_cust2"
#
#  # default upstream is internet firewall
#  upstream firewall.internal.example.com:80
#
# The LAST matching rule wins the route decision.  As you can see, you
# can use a host, or a domain:
#  name     matches host exactly
#  .name    matches any host in domain "name"
#  .        matches any host with no domain (in 'empty' domain)
#  IP/bits  matches network/mask
#  IP/mask  matches network/mask
#
#Upstream some.remote.proxy:port

# 最大客户端同时连接数
MaxClients 100

# 最小备用服务器数量.
MinSpareServers 5
# 最大备用服务器数量
MaxSpareServers 20

# 最初要启动的服务器数。
StartServers 10

# 线程被杀死之前将处理的连接数。 实际上,应将其设置为0,以禁用线程收割。 如果确实发现内存泄漏问题,则将其设置为10000。
MaxRequestsPerChild 0

# 允许访问代理的地址,注销则允许所有
#Allow 127.0.0.1

# 添加Header头部信息
#AddHeader "X-My-Header" "Powered by Tinyproxy"

# HTTP RFC要求使用“ Via”标头,但是使用真实主机名是安全问题。 如果启用以下指令,则提供的字符串将用作Via标头中的主机名; 否则,将使用服务器的主机名。
ViaProxyName "tinyproxy"

# 关闭默认Header信息
DisableViaHeader Yes

# 指定过滤器文件的位置。
Filter "/etc/tinyproxy/filter"

# 根据URL而非域进行过滤。
FilterURLs On

# 使用POSIX扩展正则表达式而不是基本表达式。
#FilterExtended On

# 使用区分大小写的正则表达式。
#FilterCaseSensitive On

# Filter内容外默认拒绝
FilterDefaultDeny No

# Anonymous: If an Anonymous keyword is present, then anonymous proxying
# is enabled.  The headers listed are allowed through, while all others
# are denied. If no Anonymous keyword is present, then all headers are
# allowed through.  You must include quotes around the headers.
#
# Most sites require cookies to be enabled for them to work correctly, so
# you will need to allow Cookies through if you access those sites.
#
#Anonymous "Host"
#Anonymous "Authorization"
#Anonymous "Cookie"

# 这是使用CONNECT方法时tinyproxy允许的端口的列表。 要完全禁用CONNECT方法,请将其值设置为0。如果未找到ConnectPort行,则允许所有端口(不是很安全)。
# SSL使用以下两个端口。
ConnectPort 443
#ConnectPort 563

# Configure one or more ReversePath directives to enable reverse proxy
# support. With reverse proxying it's possible to make a number of
# sites appear as if they were part of a single site.
# If you uncomment the following two directives and run tinyproxy
# on your own computer at port 8888, you can access Google using
# http://localhost:8888/google/ and Wired News using
# http://localhost:8888/wired/news/. Neither will actually work
# until you uncomment ReverseMagic as they use absolute linking
#ReversePath "/google/"	"http://www.google.com/"
#ReversePath "/wired/"	"http://www.wired.com/"

# 当使用tinyproxy作为反向代理时,强烈建议通过取消注释下一个指令来关闭普通代理。
#ReverseOnly Yes

# 使用cookie来跟踪反向代理映射。如果您需要反向具有绝对链接的代理站点,则必须取消注释。
#ReverseMagic Yes

# 用于访问此反向代理的URL。 该URL用于重写HTTP重定向,以使它们不会逃脱代理。 如果您有一连串的反向代理,则需要在此处放置最外面的URL(最终用户在其浏览器中键入的地址)。
# 如果未设置,则不会进行任何重写。
#ReverseBaseURL "http://localhost:8888/"

放通防火墙

firewall-cmd --zone=public --add-port=8888/tcp --permanent
firewall-cmd --reload
返回顶部
顶部