话不多说直接上干货~~~
由于 https://raw.githubusercontent.com在国内无法访问,所以需要梯一下,所以需要在wsl上使用shadowsocks的linux client客户端连接服务端(已搭建好,所以本文此处略过~,感兴趣的小伙伴可以看看 ShadowsocksR 各种客户端及服务器的配置与搭建),由于discourse需要安装 * [Git ]、* [rbenv ]、* [ruby-build ]、* [Ruby ]、* [Rails ]、* [PostgreSQL ]、* [SQLite ]、* [Redis ]、* [Bundler ]、* [MailHog ]、* [ImageMagick ]依赖,官方提供的bash脚本中很多资源都需要去外网访问下载,所以有了本文的心得记录。
1、win11 安装wsl2
直接在微软商店里搜索ubuntu20.04 LTS进行下载安装:
在应用程序中找到新安装的ubuntu打开即可,自带的终端命令行太难看了,发现了个神器 Windows Terminal,有以下优点:
- 支持WSL2,SSH,Powershell,cmd和其他命令行
- 多个选项卡和拆分窗格
- 搜索框
- 自定义键绑定
- GPU加速文字渲染
- 美观的新字体Cascadia Code
- 资源使用率低(每个选项卡通常10MB)
- 自动更新(如果使用Microsoft Store)
- 好的文档
- 它是开源的!
所以使用Windows Terminal搭配wsl,香~
2、配置wsl ubuntu20.04系统级代理
-
安装客户端依赖库
sudo apt-get install python-pip
sudo pip install shadowsocks -
编辑shadowsocks的配置文件sudo vi /etc/shadowsocks.json
然后在shadowsocks.json
里面添加配置信息,如:
{
"server":"my_server_ip",
"local_address": "0.0.0.0",
"local_port":8123,
"server_port":3306,
"password":"pwd123",
"timeout":300,
"method":"aes-256-cfb"
}
注意将my_server_ip替换为你的shadowsocks服务器IP
-
测试启动:
sslocal -c /etc/shadowsocks.json -
测试代理是否联通
curl --proxy socks5://localhost:8123 http://ipinfo.io
返回的ip是你的代理服务器IP说明代理可以正常连接。
3、 安装配置 privoxy
privoxy 能够实现不同代理之间的切换,使用它可以作为 SOCKS 代理和 HTTP、HTTPS 代理连接的桥梁,它能把所有的 http 请求(包括终端执行的命令,浏览器)转发给 shadowsocks,它就像是一个适配器,将 SOCKS 代理转为 HTTP 代理。
- 安装 privoxy
sudo apt install privoxy
- 配置 privoxy
sudo vim /etc/privoxy/config
找到 #listen-address 127.0.0.1:8118
,取消注释,表示 privoxy 监听本机 8118 端口
找到 #forward-socks5t / 127.0.0.1:9050 .
,在下方添加一行 forward-socks5t / 127.0.0.1:1080 .
,表示转发请求到本地 1080 端口,而 1080 端口是 shadowsocks 监听的端口
- 修改完后,重启 privoxy
systemctl restart privoxy
- 配置请求转发
在 ~/.bashrc
中添加如下内容,如果使用的是 zsh,则在 ~/.zshrc
中添加
set proxy
export http_proxy=“127.0.0.1:8118”
export https_proxy=“127.0.0.1:8118”
export ftp_proxy=“127.0.0.1:8118”
- 测试
谷歌可以正常返回页面html