ubuntu24.04部署代理服务(基于clash-for-linux)
ubuntu24.04部署代理服务
基于ubuntu24.04系统,需提前准备好订阅URL,最好使用root账号进行操作
推荐网址
1 |
|
1.仓库地址
1 |
|
2.部署流程
下载项目
git clone https://github.com/wnlen/clash-for-linux.git
网络不允许的条件下,进入github.com下载zip包
解压并进入目录
unzip clash-for-linux-master.zip
cd clash-for-linux-master
编辑配置文件
修改变量CLASH_URL的值,即订阅URL
vi .env
注意: .env 文件中的变量 CLASH_SECRET 为自定义 Clash Secret,值为空时,脚本将自动生成随机字符串。
赋予脚本执行权限
chmod +x start.sh
chmod +x shutdown.sh
chmod +x restart.sh
启动程序
bash start.sh
1 |
|
加载环境变量
source /etc/profile.d/clash.sh
开启代理
proxy_on
检查服务端口和环境变量
netstat -tln | grep -E '9090|789.'
env | grep -E 'http_proxy|https_proxy'
重启程序
如果需要对Clash配置进行修改,请修改 conf/config.yaml 文件。然后运行 restart.sh 脚本进行重启。
注意: 重启脚本 restart.sh 不会更新订阅信息。
停止程序
bash shutdown.sh
proxy_off
检查服务端口和环境变量
3.网页访问
1 |
|
配置访问链接
填入URL和Secret后点击ADD,然后在下方列表中即可点击进入,Secret可以在启动日志或conf/config.yaml中进行查看
4.docker容器测试(可选)
配置docker镜像使用该代理
设置systemd
cd /etc/systemd/system
mkdir docker.service.d
cd docker.service.d
vi http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://127.0.0.1:7890"
Environment="HTTPS_PROXY=http://127.0.0.1:7890"
重新加载docker
sudo systemctl daemon-reload
sudo systemctl restart docker
docker compose容器单独配置宿主机代理
配置文件修改:
environment:
- http_proxy=http://172.17.0.1:7890
- https_proxy=http://172.17.0.1:7890
容器网络连通性验证
docker exec -it newsnow nc -zv 172.17.0.1 7890
容器内部验证
docker exec -it newsnow sh
env | grep -i proxy
nc -zv 172.17.0.1 7890
容器工具安装测试
apk add curl
curl -v https://www.google.com
5.dify设置代理(可选)
ssrf_proxy 是 Dify 架构中的 安全网关,通过 Squid 代理实现:
流量管控:强制内部服务通过代理访问外部。
访问控制:限制可访问的外部域名。
反向代理:安全暴露 sandbox 服务。
因此需要在 Squid 中配置上游代理
修改dify/docker/ssrf_proxy下的squid.conf.template,在末尾加入
cache_peer 172.17.0.1 parent 8118 0 no-query default
never_direct allow all
解决插件安装问题
修改dify/docker/下的.env,取消注释
PIP_MIRROR_URL=https://pypi.tuna.tsinghua.edu.cn/simple
修改完毕后,重新启动服务
docker compose down
docker compose up -d
6.docker构建镜像时设置代理(可选)
docker build --no-cache --build-arg HTTP_PROXY=http://172.17.0.1:8118 --build-arg HTTPS_PROXY=http://172.17.0.1:8118 -t newsnow:1.0.0 .
docker build --no-cache --build-arg HTTP_PROXY=http://172.17.0.1:7890 --build-arg HTTPS_PROXY=http://172.17.0.1:7890 -t newsnow:1.0.0 .
ubuntu24.04部署代理服务(基于clash-for-linux)
http://example.com/2025/03/31/ubuntu24.04-remoteProxyByServer/