用tinyproxy搭建HTTP前向代理

原理

HTTP前向代理(HTTP Forward Proxy Server)是转发HTTP请求的服务器,其流程

                        --- Request --->
+-----------+           +--------------+           +-----------+
|           | --------> |              | --------> |           |
|  Browser  |           | Proxy Server |           |  Website  |
|           | <-------- |              | <-------- |           |
+-----------+           +--------------+           +-----------+
                        <-- Response ---

在OpenBSD上配置tinyproxy

安装tinyproxy,OpenBSD上已将其整合到rcctl。

# pkg_add tinyproxy
quirks-7.194 signed on 2026-06-10T19:46:25Z
tinyproxy-1.11.3: ok
The following new rcscripts were installed: /etc/rc.d/tinyproxy
See rcctl(8) for details.

启动tinyproxy

# rcctl enable tinyproxy
# rcctl start tinyproxy

检查tinyproxy正常运行

$ curl http://localhost:8888
...
<head>
<title>400 Bad Request</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>

<body>
<h1>Bad Request</h1>
<p>You tried to connect to the machine the proxy is running on</p>
<hr />
<p><em>Generated by <a href="https://tinyproxy.github.io/">tinyproxy</a>.</em></p>
</body>

</html>

如上,tinyproxy已正常工作。但从其它地方访问,会收到Access Deny的提示。

需修改tinyproxy.conf,允许任何ip访问此proxy

# vim /etc/tinyproxy/tinyproxy.conf
~~~
  # Allow 127.0.0.1  <-- 注释掉这两句
  # Allow ::1
~~~

# rcctl restart tinyproxy

科学上网

在Windows上配置http代理,通过浏览器访问的地址,就自动走代理了。

访问whatismyip网站,查看ip信息,能知道是否走了代理。