Linux工具-Tinyproxy服务器

打印 上一主题 下一主题

主题 867|帖子 867|积分 2601

https://github.com/tinyproxy/tinyproxy
Tinyproxy is a light-weight HTTP/HTTPS proxy daemon for POSIX operating systems. Designed from the ground up to be fast and yet small, it is an ideal solution for use cases such as embedded deployments where a full featured HTTP proxy is required, but the system resources for a larger proxy are unavailable.
Tinyproxy是为POSIX操作系统的设计的一个轻量级HTTP/HTTPS署理服务器(守卫进程)。它的设计初衷是快速而小巧,它为必要功能齐全的HTTP署理但不能提供较大署理资源的嵌入式系统提供了一个好的办理方案。
一、安装

Huawei Cloud Ubuntu 20.04:
  1. sudo apt install tinyproxy
复制代码
二、配置更新

tinyproxy安装完成了,可以在系统中找到三个文件:


  • /lib/systemd/system/tinyproxy.service
  • /etc/default/tinyproxy
  • /etc/tinyproxy/tinyproxy.conf
    根据测试验证,这些配置文件必要根据实际运行环境做必要调解。
/lib/systemd/system/tinyproxy.service
  1. [Unit]
  2. Description=Tinyproxy lightweight HTTP Proxy
  3. After=network.target
  4. Documentation=man:tinyproxy(8) man:tinyproxy.conf(5)
  5. [Service]
  6. PassEnvironment=-/etc/default/tinyproxy
  7. Type=forking
  8. ExecStart=/usr/bin/tinyproxy $FLAGS
  9. PIDFile=/run/tinyproxy/tinyproxy.pid
  10. PrivateDevices=yes
  11. User=root
  12. [Install]
  13. WantedBy=multi-user.target
复制代码
/etc/default/tinyproxy
  1. ### tinyproxy defaults
  2. # Edit to configure alternate config file...
  3. #
  4. # If running under systemd, please make sure to uncomment
  5. # both variables below!
  6. CONFIG="/etc/tinyproxy/tinyproxy.conf"
  7. FLAGS="-c $CONFIG"
  8. # Add more command line options, as desired...
  9. #FLAGS="$FLAGS ..."
复制代码
** /etc/tinyproxy/tinyproxy.conf**
  1. ##
  2. ## tinyproxy.conf -- tinyproxy daemon configuration file
  3. ##
  4. ## This example tinyproxy.conf file contains example settings
  5. ## with explanations in comments. For decriptions of all
  6. ## parameters, see the tinproxy.conf(5) manual page.
  7. ##
  8. #
  9. # User/Group: This allows you to set the user and group that will be
  10. # used for tinyproxy after the initial binding to the port has been done
  11. # as the root user. Either the user or group name or the UID or GID
  12. # number may be used.
  13. #
  14. User root
  15. Group root
  16. #
  17. # Port: Specify the port which tinyproxy will listen on.  Please note
  18. # that should you choose to run on a port lower than 1024 you will need
  19. # to start tinyproxy using root.
  20. #
  21. Port 8888
  22. #
  23. # Listen: If you have multiple interfaces this allows you to bind to
  24. # only one. If this is commented out, tinyproxy will bind to all
  25. # interfaces present.
  26. #
  27. #Listen 192.168.0.1
  28. #
  29. # Bind: This allows you to specify which interface will be used for
  30. # outgoing connections.  This is useful for multi-home'd machines where
  31. # you want all traffic to appear outgoing from one particular interface.
  32. #
  33. #Bind 192.168.0.1
  34. #
  35. # BindSame: If enabled, tinyproxy will bind the outgoing connection to the
  36. # ip address of the incoming connection.
  37. #
  38. #BindSame yes
  39. #
  40. # Timeout: The maximum number of seconds of inactivity a connection is
  41. # allowed to have before it is closed by tinyproxy.
  42. #
  43. Timeout 600
  44. #
  45. # ErrorFile: Defines the HTML file to send when a given HTTP error
  46. # occurs.  You will probably need to customize the location to your
  47. # particular install.  The usual locations to check are:
  48. #   /usr/local/share/tinyproxy
  49. #   /usr/share/tinyproxy
  50. #   /etc/tinyproxy
  51. #
  52. #ErrorFile 404 "/usr/share/tinyproxy/404.html"
  53. #ErrorFile 400 "/usr/share/tinyproxy/400.html"
  54. #ErrorFile 503 "/usr/share/tinyproxy/503.html"
  55. #ErrorFile 403 "/usr/share/tinyproxy/403.html"
  56. #ErrorFile 408 "/usr/share/tinyproxy/408.html"
  57. #
  58. # DefaultErrorFile: The HTML file that gets sent if there is no
  59. # HTML file defined with an ErrorFile keyword for the HTTP error
  60. # that has occured.
  61. #
  62. DefaultErrorFile "/usr/share/tinyproxy/default.html"
  63. #
  64. # StatHost: This configures the host name or IP address that is treated
  65. # as the stat host: Whenever a request for this host is received,
  66. # Tinyproxy will return an internal statistics page instead of
  67. # forwarding the request to that host.  The default value of StatHost is
  68. # tinyproxy.stats.
  69. #
  70. #StatHost "tinyproxy.stats"
  71. #
  72. #
  73. # StatFile: The HTML file that gets sent when a request is made
  74. # for the stathost.  If this file doesn't exist a basic page is
  75. # hardcoded in tinyproxy.
  76. #
  77. StatFile "/usr/share/tinyproxy/stats.html"
  78. #
  79. # LogFile: Allows you to specify the location where information should
  80. # be logged to.  If you would prefer to log to syslog, then disable this
  81. # and enable the Syslog directive.  These directives are mutually
  82. # exclusive. If neither Syslog nor LogFile are specified, output goes
  83. # to stdout.
  84. #
  85. LogFile "/var/log/tinyproxy/tinyproxy.log"
  86. #
  87. # Syslog: Tell tinyproxy to use syslog instead of a logfile.  This
  88. # option must not be enabled if the Logfile directive is being used.
  89. # These two directives are mutually exclusive.
  90. #
  91. #Syslog On
  92. #
  93. # LogLevel: Warning
  94. #
  95. # Set the logging level. Allowed settings are:
  96. #       Critical        (least verbose)
  97. #       Error
  98. #       Warning
  99. #       Notice
  100. #       Connect         (to log connections without Info's noise)
  101. #       Info            (most verbose)
  102. #
  103. # The LogLevel logs from the set level and above. For example, if the
  104. # LogLevel was set to Warning, then all log messages from Warning to
  105. # Critical would be output, but Notice and below would be suppressed.
  106. #
  107. LogLevel Info
  108. #
  109. # PidFile: Write the PID of the main tinyproxy thread to this file so it
  110. # can be used for signalling purposes.
  111. # If not specified, no pidfile will be written.
  112. #
  113. PidFile "/run/tinyproxy/tinyproxy.pid"
  114. #
  115. # XTinyproxy: Tell Tinyproxy to include the X-Tinyproxy header, which
  116. # contains the client's IP address.
  117. #
  118. #XTinyproxy Yes
  119. #
  120. # Upstream:
  121. #
  122. # Turns on upstream proxy support.
  123. #
  124. # The upstream rules allow you to selectively route upstream connections
  125. # based on the host/domain of the site being accessed.
  126. #
  127. # Syntax: upstream type (user:pass@)ip:port ("domain")
  128. # Or:     upstream none "domain"
  129. # The parts in parens are optional.
  130. # Possible types are http, socks4, socks5, none
  131. #
  132. # For example:
  133. #  # connection to test domain goes through testproxy
  134. #  upstream http testproxy:8008 ".test.domain.invalid"
  135. #  upstream http testproxy:8008 ".our_testbed.example.com"
  136. #  upstream http testproxy:8008 "192.168.128.0/255.255.254.0"
  137. #
  138. #  # upstream proxy using basic authentication
  139. #  upstream http user:pass@testproxy:8008 ".test.domain.invalid"
  140. #
  141. #  # no upstream proxy for internal websites and unqualified hosts
  142. #  upstream none ".internal.example.com"
  143. #  upstream none "www.example.com"
  144. #  upstream none "10.0.0.0/8"
  145. #  upstream none "192.168.0.0/255.255.254.0"
  146. #  upstream none "."
  147. #
  148. #  # connection to these boxes go through their DMZ firewalls
  149. #  upstream http cust1_firewall:8008 "testbed_for_cust1"
  150. #  upstream http cust2_firewall:8008 "testbed_for_cust2"
  151. #
  152. #  # default upstream is internet firewall
  153. #  upstream http firewall.internal.example.com:80
  154. #
  155. # You may also use SOCKS4/SOCKS5 upstream proxies:
  156. #  upstream socks4 127.0.0.1:9050
  157. #  upstream socks5 socksproxy:1080
  158. #
  159. # The LAST matching rule wins the route decision.  As you can see, you
  160. # can use a host, or a domain:
  161. #  name     matches host exactly
  162. #  .name    matches any host in domain "name"
  163. #  .        matches any host with no domain (in 'empty' domain)
  164. #  IP/bits  matches network/mask
  165. #  IP/mask  matches network/mask
  166. #
  167. #Upstream http some.remote.proxy:port
  168. #
  169. # MaxClients: This is the absolute highest number of threads which will
  170. # be created. In other words, only MaxClients number of clients can be
  171. # connected at the same time.
  172. #
  173. MaxClients 100
  174. #
  175. # MinSpareServers/MaxSpareServers: These settings set the upper and
  176. # lower limit for the number of spare servers which should be available.
  177. #
  178. # If the number of spare servers falls below MinSpareServers then new
  179. # server processes will be spawned.  If the number of servers exceeds
  180. # MaxSpareServers then the extras will be killed off.
  181. #
  182. MinSpareServers 5
  183. MaxSpareServers 20
  184. #
  185. # StartServers: The number of servers to start initially.
  186. #
  187. StartServers 10
  188. #
  189. # MaxRequestsPerChild: The number of connections a thread will handle
  190. # before it is killed. In practise this should be set to 0, which
  191. # disables thread reaping. If you do notice problems with memory
  192. # leakage, then set this to something like 10000.
  193. #
  194. MaxRequestsPerChild 0
  195. #
  196. # Allow: Customization of authorization controls. If there are any
  197. # access control keywords then the default action is to DENY. Otherwise,
  198. # the default action is ALLOW.
  199. #
  200. # The order of the controls are important. All incoming connections are
  201. # tested against the controls based on order.
  202. #
  203. #Allow 127.0.0.1
  204. #Allow 192.168.0.0/16
  205. #Allow 172.16.0.0/12
  206. #Allow 10.0.0.0/8
  207. # BasicAuth: HTTP "Basic Authentication" for accessing the proxy.
  208. # If there are any entries specified, access is only granted for authenticated
  209. # users.
  210. #BasicAuth user password
  211. #
  212. # AddHeader: Adds the specified headers to outgoing HTTP requests that
  213. # Tinyproxy makes. Note that this option will not work for HTTPS
  214. # traffic, as Tinyproxy has no control over what headers are exchanged.
  215. #
  216. #AddHeader "X-My-Header" "Powered by Tinyproxy"
  217. #
  218. # ViaProxyName: The "Via" header is required by the HTTP RFC, but using
  219. # the real host name is a security concern.  If the following directive
  220. # is enabled, the string supplied will be used as the host name in the
  221. # Via header; otherwise, the server's host name will be used.
  222. #
  223. ViaProxyName "tinyproxy"
  224. #
  225. # DisableViaHeader: When this is set to yes, Tinyproxy does NOT add
  226. # the Via header to the requests. This virtually puts Tinyproxy into
  227. # stealth mode. Note that RFC 2616 requires proxies to set the Via
  228. # header, so by enabling this option, you break compliance.
  229. # Don't disable the Via header unless you know what you are doing...
  230. #
  231. #DisableViaHeader Yes
  232. #
  233. # Filter: This allows you to specify the location of the filter file.
  234. #
  235. #Filter "/etc/tinyproxy/filter"
  236. #
  237. # FilterURLs: Filter based on URLs rather than domains.
  238. #
  239. #FilterURLs On
  240. #
  241. # FilterExtended: Use POSIX Extended regular expressions rather than
  242. # basic.
  243. #
  244. #FilterExtended On
  245. #
  246. # FilterCaseSensitive: Use case sensitive regular expressions.
  247. #
  248. #FilterCaseSensitive On
  249. #
  250. # FilterDefaultDeny: Change the default policy of the filtering system.
  251. # If this directive is commented out, or is set to "No" then the default
  252. # policy is to allow everything which is not specifically denied by the
  253. # filter file.
  254. #
  255. # However, by setting this directive to "Yes" the default policy becomes
  256. # to deny everything which is _not_ specifically allowed by the filter
  257. # file.
  258. #
  259. #FilterDefaultDeny Yes
  260. #
  261. # Anonymous: If an Anonymous keyword is present, then anonymous proxying
  262. # is enabled.  The headers listed are allowed through, while all others
  263. # are denied. If no Anonymous keyword is present, then all headers are
  264. # allowed through.  You must include quotes around the headers.
  265. #
  266. # Most sites require cookies to be enabled for them to work correctly, so
  267. # you will need to allow Cookies through if you access those sites.
  268. #
  269. #Anonymous "Host"
  270. #Anonymous "Authorization"
  271. #Anonymous "Cookie"
  272. #
  273. # ConnectPort: This is a list of ports allowed by tinyproxy when the
  274. # CONNECT method is used.  To disable the CONNECT method altogether, set
  275. # the value to 0.  If no ConnectPort line is found, all ports are
  276. # allowed.
  277. #
  278. # The following two ports are used by SSL.
  279. #
  280. ConnectPort 443
  281. ConnectPort 563
  282. #
  283. # Configure one or more ReversePath directives to enable reverse proxy
  284. # support. With reverse proxying it's possible to make a number of
  285. # sites appear as if they were part of a single site.
  286. #
  287. # If you uncomment the following two directives and run tinyproxy
  288. # on your own computer at port 8888, you can access Google using
  289. # http://localhost:8888/google/ and Wired News using
  290. # http://localhost:8888/wired/news/. Neither will actually work
  291. # until you uncomment ReverseMagic as they use absolute linking.
  292. #
  293. # ReversePath "/google/"        "http://www.google.com/"
  294. # ReversePath "/wired/"                "http://www.wired.com/"
  295. #
  296. # When using tinyproxy as a reverse proxy, it is STRONGLY recommended
  297. # that the normal proxy is turned off by uncommenting the next directive.
  298. #
  299. #ReverseOnly Yes
  300. #
  301. # Use a cookie to track reverse proxy mappings. If you need to reverse
  302. # proxy sites which have absolute links you must uncomment this.
  303. #
  304. #ReverseMagic Yes
  305. #
  306. # The URL that's used to access this reverse proxy. The URL is used to
  307. # rewrite HTTP redirects so that they won't escape the proxy. If you
  308. # have a chain of reverse proxies, you'll need to put the outermost
  309. # URL here (the address which the end user types into his/her browser).
  310. #
  311. # If not set then no rewriting occurs.
  312. #
  313. #ReverseBaseURL "http://localhost:8888/"
复制代码
注:tinyproxy的具体配置介绍可参考:https://tinyproxy.github.io/
三、服务管理

ubuntu环境下,tinyproxy默认利用systemd进行管理。
  1. # 启动进程
  2. sudo systemctl start tinyproxy
  3. # 停止进程
  4. sudo systemctl stop tinyproxy
  5. # 重启进程
  6. sudo systemctl restart tinyproxy
  7. # 查看状态
  8. sudo systemctl status tinyproxy
  9. # 查看systemd日志
  10. sudo journalctl -u tinyproxy.service -f
复制代码
注:查看tinyproxy实时日记输出:tail -f /var/log/tinyproxy/tinyproxy.log

四、测试验证

tinyproxy日记实时监控:
  1. tail -f /var/log/tinyproxy/tinyproxy.log
复制代码
1、command line

1、设置环境变量
  1. export http_proxy="http://xxx.xxx.xxx.xxx:8888/"
  2. export https_proxy="http://xxx.xxx.xxx.xxx:8888/"
复制代码
2、wget访问网络·
  1. wget baidu.com
复制代码
3、观测日记输出

2、firefox browser

1、设置署理服务器
打开浏览器,依次点击“Settings” -》 “General” -》 “Network Settings” -》 “Settings”,选择“Manual proxy configuration”并设置正确的署理服务器ip和端口。

2、访问百度首页(www.baidu.con)
3、观测日记输出

五、应用场景





免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

光之使者

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表