<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>HTTP代理 &#8211; 编码无悔 /  Intent &amp; Focused</title>
	<atom:link href="https://www.codelast.com/tag/http%E4%BB%A3%E7%90%86/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.codelast.com</link>
	<description>最优化之路</description>
	<lastBuildDate>Sat, 01 Jan 2022 12:57:07 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>[原创] 在腾讯云的轻量应用服务器Lighthouse上用Squid开启HTTP代理服务</title>
		<link>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%9c%a8%e8%85%be%e8%ae%af%e4%ba%91%e7%9a%84%e8%bd%bb%e9%87%8f%e5%ba%94%e7%94%a8%e6%9c%8d%e5%8a%a1%e5%99%a8lighthouse%e4%b8%8a%e7%94%a8squid%e5%bc%80%e5%90%afhttp%e4%bb%a3/</link>
					<comments>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%9c%a8%e8%85%be%e8%ae%af%e4%ba%91%e7%9a%84%e8%bd%bb%e9%87%8f%e5%ba%94%e7%94%a8%e6%9c%8d%e5%8a%a1%e5%99%a8lighthouse%e4%b8%8a%e7%94%a8squid%e5%bc%80%e5%90%afhttp%e4%bb%a3/#respond</comments>
		
		<dc:creator><![CDATA[learnhard]]></dc:creator>
		<pubDate>Mon, 15 Mar 2021 18:58:01 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[综合]]></category>
		<category><![CDATA[HTTP代理]]></category>
		<category><![CDATA[Lighthouse]]></category>
		<category><![CDATA[Squid]]></category>
		<category><![CDATA[腾讯云]]></category>
		<category><![CDATA[轻量应用服务器]]></category>
		<guid isPermaLink="false">https://www.codelast.com/?p=13272</guid>

					<description><![CDATA[<p>前段时间我看到腾讯云的促销广告，其&#8220;<a href="https://cloud.tencent.com/product/lighthouse" rel="noopener" target="_blank">轻量应用服务器</a>&#8221;首年的费用才85元（配置：1核CPU，2GB内存，50GB磁盘，带宽4Mbps，流量包500GB/月），可谓相当便宜，于是入手一台，安装了Ubuntu系统，用于一些简单的测试场景。</p>
<blockquote>
<p>
		轻量应用服务器（Lighthouse）是新一代面向中小企业和开发者的云服务器产品，具备轻运维、开箱即用的特点，适用于小型网站、博客、论坛、电商以及云端开发测试和学习环境等轻量级业务场景，相比传统云服务器更加简单易用，并通过一站式融合常用基础云服务帮助用户便捷高效的构建应用，是您使用腾讯云的最佳入门途径。&#160;</p>
</blockquote>
<p><span id="more-13272"></span><br />
入手后的第一个用途是用Squid搭建一个HTTP代理服务。</p>
<blockquote>
<p>
		Squid是一个高性能的代理缓存服务器，Squid支持FTP、gopher、HTTPS和HTTP协议。</p>
</blockquote>
<p>Squid非常流行，并且可以配置成：使用代理的时候，要输入用户名、密码才能连接。有的后起之秀代理服务器软件功能没有这么强大，不能支持账号访问模式，所以就不用去折腾了。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color:#ff0000;">✔</span> 安装Squid</p>
<blockquote>
<p>
		sudo apt install squid</p>
</blockquote>
<p>
<span style="color: rgb(255, 0, 0);">✔</span>&#160;配置Squid：代理服务的端口</p>
<blockquote>
<p>
		sudo vim /etc/squid/squid.conf</p>
</blockquote>
<p>该配置文件的&#8220;http_port 3128&#8221;定义了默认的服务端口为3128，你可以改成你想要的端口。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);">✔</span>&#160;创建密码<br />
为了通过用户名、密码来访问代理服务器，需要先安装软件包：</p>
<blockquote>
<p>
		sudo apt install apache2-utils</p>
</blockquote>
<p>这个软件包有创建密码所需的&#160;htpasswd&#160;软件。<br />
然后就可以创建密码文件了：</p>
<blockquote>
<p>
		sudo htpasswd -c -d /etc/squid/passwd &#60;username&#62;</p>
</blockquote>
<p>这里表示的是：生成一个密码文件&#160;/etc/squid/passwd，访问代理的用户名是 &#60;username&#62;，你自己看情况设置。<br />
注意：<br />
（1）为了避免麻烦，密码应设置成8位字符。据说不是8位的话会有warning，并且会有验证问题。<br />
（2）你会发现，/etc/squid/passwd 这个密码文件里的密码内容，并不是你前面输入的密码！在客户端使用Squid代理的时候，使用的是你输入的密码，而不是&#160;/etc/squid/passwd&#160;文件里的密码！<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a>&#8230; <a href="https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%9c%a8%e8%85%be%e8%ae%af%e4%ba%91%e7%9a%84%e8%bd%bb%e9%87%8f%e5%ba%94%e7%94%a8%e6%9c%8d%e5%8a%a1%e5%99%a8lighthouse%e4%b8%8a%e7%94%a8squid%e5%bc%80%e5%90%afhttp%e4%bb%a3/" class="read-more">Read More </a></p>]]></description>
										<content:encoded><![CDATA[<p>前段时间我看到腾讯云的促销广告，其&ldquo;<a href="https://cloud.tencent.com/product/lighthouse" rel="noopener" target="_blank">轻量应用服务器</a>&rdquo;首年的费用才85元（配置：1核CPU，2GB内存，50GB磁盘，带宽4Mbps，流量包500GB/月），可谓相当便宜，于是入手一台，安装了Ubuntu系统，用于一些简单的测试场景。</p>
<blockquote>
<p>
		轻量应用服务器（Lighthouse）是新一代面向中小企业和开发者的云服务器产品，具备轻运维、开箱即用的特点，适用于小型网站、博客、论坛、电商以及云端开发测试和学习环境等轻量级业务场景，相比传统云服务器更加简单易用，并通过一站式融合常用基础云服务帮助用户便捷高效的构建应用，是您使用腾讯云的最佳入门途径。&nbsp;</p>
</blockquote>
<p><span id="more-13272"></span><br />
入手后的第一个用途是用Squid搭建一个HTTP代理服务。</p>
<blockquote>
<p>
		Squid是一个高性能的代理缓存服务器，Squid支持FTP、gopher、HTTPS和HTTP协议。</p>
</blockquote>
<p>Squid非常流行，并且可以配置成：使用代理的时候，要输入用户名、密码才能连接。有的后起之秀代理服务器软件功能没有这么强大，不能支持账号访问模式，所以就不用去折腾了。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color:#ff0000;"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2714.png" alt="✔" class="wp-smiley" style="height: 1em; max-height: 1em;" /></span> 安装Squid</p>
<blockquote>
<p>
		sudo apt install squid</p>
</blockquote>
<p>
<span style="color: rgb(255, 0, 0);"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2714.png" alt="✔" class="wp-smiley" style="height: 1em; max-height: 1em;" /></span>&nbsp;配置Squid：代理服务的端口</p>
<blockquote>
<p>
		sudo vim /etc/squid/squid.conf</p>
</blockquote>
<p>该配置文件的&ldquo;http_port 3128&rdquo;定义了默认的服务端口为3128，你可以改成你想要的端口。<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2714.png" alt="✔" class="wp-smiley" style="height: 1em; max-height: 1em;" /></span>&nbsp;创建密码<br />
为了通过用户名、密码来访问代理服务器，需要先安装软件包：</p>
<blockquote>
<p>
		sudo apt install apache2-utils</p>
</blockquote>
<p>这个软件包有创建密码所需的&nbsp;htpasswd&nbsp;软件。<br />
然后就可以创建密码文件了：</p>
<blockquote>
<p>
		sudo htpasswd -c -d /etc/squid/passwd &lt;username&gt;</p>
</blockquote>
<p>这里表示的是：生成一个密码文件&nbsp;/etc/squid/passwd，访问代理的用户名是 &lt;username&gt;，你自己看情况设置。<br />
注意：<br />
（1）为了避免麻烦，密码应设置成8位字符。据说不是8位的话会有warning，并且会有验证问题。<br />
（2）你会发现，/etc/squid/passwd 这个密码文件里的密码内容，并不是你前面输入的密码！在客户端使用Squid代理的时候，使用的是你输入的密码，而不是&nbsp;/etc/squid/passwd&nbsp;文件里的密码！<br />
<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
<span style="color: rgb(255, 0, 0);"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2714.png" alt="✔" class="wp-smiley" style="height: 1em; max-height: 1em;" /></span>&nbsp;配置Squid：设置使用密码文件定义的账号</p>
<blockquote>
<p>
		sudo vim /etc/squid/squid.conf</p>
</blockquote>
<div>
	在 <span style="color:#0000ff;"># INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS</span>&nbsp;这句话下添加：</div>
<blockquote>
<div>
		auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/passwd</div>
<div>
		acl auth_user proxy_auth REQUIRED</div>
<div>
		http_access allow auth_user</div>
</blockquote>
<div>
	并确保后面的两句是没有被注释掉的：</div>
<blockquote>
<div>
		http_access allow localhost<br />
		http_access deny all</div>
</blockquote>
<div>
	第一句是允许在云服务器本地访问代理服务，第二句是禁止其他一切流量对该代理服务器的访问，也就是说：只有使用前面在密码文件中定义的账号，才能访问该代理服务器。</div>
<div>
	<br />
	<span style="color: rgb(255, 0, 0);"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2714.png" alt="✔" class="wp-smiley" style="height: 1em; max-height: 1em;" /></span>&nbsp;启动代理服务</div>
<blockquote>
<div>
		service squid start</div>
</blockquote>
<div>
	<br />
	<span style="color: rgb(255, 0, 0);"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2714.png" alt="✔" class="wp-smiley" style="height: 1em; max-height: 1em;" /></span>&nbsp;查看Squid日志<br />
	首先在Squid配置文件中打开日志记录，取消注释下面这行：</div>
<blockquote>
<div>
		access_log daemon:/var/log/squid/access.log squid</div>
</blockquote>
<div>
	再重启Squid服务（service squid restart），然后即可查看：</div>
<blockquote>
<div>
		tail -f /var/log/squid/access.log</div>
</blockquote>
<div>
	<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
	<span style="color: rgb(255, 0, 0);"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2714.png" alt="✔" class="wp-smiley" style="height: 1em; max-height: 1em;" /></span>&nbsp;命令行测试代理服务器是否work</p>
<blockquote>
<div>
			curl -x &quot;http://用户名:密码@IP:port&quot; https://www.baidu.com</div>
</blockquote>
<div>
		其中，<span style="color:#ff0000;">IP</span> 是Squid所在的服务器的IP，<span style="color:#ff0000;">port</span> 是前面设置的代理服务端口，<span style="color:#ff0000;">用户名</span> 是前面设置的代理账号的用户名，<span style="color:#ff0000;">密码</span> 则为代理账号的密码。<br />
		能打印出网页内容即说明代理可用。</p>
<p>		<span style="color: rgb(255, 0, 0);"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2714.png" alt="✔" class="wp-smiley" style="height: 1em; max-height: 1em;" /></span>&nbsp;开放代理服务的端口给外网<br />
		这是最重要的一步！如果你没有意识到这个问题，那会浪费你非常多时间调试。<br />
		经过上面的配置，你只能在服务器上用命令行来访问代理服务，在外网仍然是不通的。此时，需要在腾讯云轻量应用服务器的&ldquo;防火墙&rdquo;设置页面，添加一条自定义的规则，开放你的代理端口：<br />
		<img decoding="async" alt="tencent cloud firewall setting" src="https://www.codelast.com/wp-content/uploads/2021/03/tencent_cloud_firewall_setting.png" style="width: 600px; height: 297px;" /><br />
		<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
		<span style="color: rgb(255, 0, 0);"><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2714.png" alt="✔" class="wp-smiley" style="height: 1em; max-height: 1em;" /></span>&nbsp;在其他机器上使用浏览器访问代理服务<br />
		假设你使用的是Chrome，那么访问代理可以用&nbsp;SwitchyOmega&nbsp;插件，新建一个情景模式，按下面的样子，把IP地址换成Squid服务所在的服务器IP，端口换成你设置的代理服务端口：<br />
		<img decoding="async" alt="switchy omega setting" src="https://www.codelast.com/wp-content/uploads/2021/03/tencent_cloud_proxy_switchy_omega_setting.png" style="width: 600px; height: 201px;" /><br />
		在使用这个情景模式的情况下，第一次用浏览器访问任何网页会弹出账号输入框，如果输对了就能通过代理来访问网络啦（可以看Squid的日志验证这一点）。<br />
		<span style="color: rgb(255, 255, 255);">文章来源：</span><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><span style="color: rgb(255, 255, 255);">https://www.codelast.com/</span></a><br />
		<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;版权声明&nbsp;<span style="color: rgb(255, 0, 0);">➤➤</span>&nbsp;<br />
		转载需注明出处：<u><a href="https://www.codelast.com/" rel="noopener noreferrer" target="_blank"><em><span style="color: rgb(0, 0, 255);"><strong style="font-size: 16px;"><span style="font-family: arial, helvetica, sans-serif;">codelast.com</span></strong></span></em></a></u>&nbsp;<br />
		感谢关注我的微信公众号（微信扫一扫）：<br />
		<img decoding="async" alt="wechat qrcode of codelast" src="https://www.codelast.com/codelast_wechat_qr_code.jpg" style="color: rgb(77, 77, 77); font-size: 13px; width: 200px; height: 200px;" /><br />
		以及我的微信视频号：</p>
<p style="border: 0px; font-size: 13px; margin: 0px 0px 9px; outline: 0px; padding: 0px; color: rgb(77, 77, 77);">
			<img decoding="async" alt="" src="https://www.codelast.com/wechat_shipinhao_qr_code.jpg" style="text-align: center; width: 200px; height: 199px;" /></p>
</p></div>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.codelast.com/%e5%8e%9f%e5%88%9b-%e5%9c%a8%e8%85%be%e8%ae%af%e4%ba%91%e7%9a%84%e8%bd%bb%e9%87%8f%e5%ba%94%e7%94%a8%e6%9c%8d%e5%8a%a1%e5%99%a8lighthouse%e4%b8%8a%e7%94%a8squid%e5%bc%80%e5%90%afhttp%e4%bb%a3/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
