有序集合

Blunt

BlockGFW安装教程

8
2024-12-11
## 安装要求

安装环境需满足以下要求:

*  x64架构

*  ubuntu20.04系统

*  已安装wget

*  已安装Nginx

*  已安装vim

*  域名已解析到本机

其他架构可下载源码自行编译。

## 安装blockgfw

查看当前路径:

```shell

ubuntu@ip-172-26-35-98:~$ pwd

/home/ubuntu

ubuntu@ip-172-26-35-98:~$

创建文件夹:

mkdir blockgfw && cd blockgfw

下载程序:

wget https://github.com/lhuang001/blockgfw/releases/latest/download/blockgfw

添加可执行权限:

sudo chmod +x blockgfw

创建blockgfw服务:

sudo vim /etc/systemd/system/blockgfw.service

向文件中写入:

[Unit]

Description=block gfw detecting

After=network.target

[Service]

Type=simple

User=root

Restart=always

RestartSec=3

WorkingDirectory=/home/ubuntu/blockgfw

ExecStart=/home/ubuntu/blockgfw/blockgfw start -s 127.0.0.1 -u userKey -a adminKey -p protectPort --reverse True

[Install]

WantedBy=multi-user.target

酌情替换:

  • 127.0.0.1: blockgfw仅监听本地端口
  • userKey: 用户密码,可自行指定
  • adminKey:管理员key,用户管理IP白名单
  • protectPort: 需要保护的端口,一般设置为v2ray监听端口
  • --reverse: 可选项,仅在开启反向代理时使用

填写科学上网链接:

echo "passWallLink" > raw.subscription

echo "clashSubscription"  > clash.subscription
  • passWallLink: 你科学上网工具的链接,v2ray为vmess开头。如果没有可留空
  • clashSubscription: clash订阅链接。没有可留空

使blockgfw服务自动启动:

sudo systemctl daemon-reload

sudo systemctl enable blockgfw

sudo systemctl start blockgfw

安装Nginx

安装命令:

sudo apt install nginx -y

新建文件,用于存放访问日志和错误日志:

sudo mkdir -p /www/yourDomain

新建nginx配置文件:

sudo vim /etc/nginx/conf.d/yourDomain.conf

并向其中写入:

server {   

    listen 80;

    server_name yourDomain;

    index index.php index.html index.htm default.php default.htm default.html;

    root /www/yourDomain;

    # Forbidden files or directories

    location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)

    {   

        return 404;

    }   

    # 反向代理blockgfw

    location / {

        proxy_pass http://127.0.0.1:8080;    #8080为blockgfw的服务端口

        proxy_redirect off;

        proxy_set_header Host $host;

        proxy_set_header X-Real-IP $remote_addr;

        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_set_header X-Forwarded-Proto $scheme;

    }

    access_log  /www/yourDomain/access.log;

    error_log  /www/yourDomain/error.log;

}

注意:yourDomain请修改为你已解析的域名

测试nginx配置文件是否正确:

ubuntu@ip-172-26-35-98:~$ sudo nginx -t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

nginx: configuration file /etc/nginx/nginx.conf test is successful

重新加载nginx使配置生效:

sudo systemctl reload nginx

效果检测

ubuntu@ip-172-26-35-98:~$ curl http://yourDomain/

SelfHelp iptables Whitelist

/api/add?key=yourkey

/api/list?key=yourkey

/api/remove/ip?key=yourkey

/api/log?key=yourkey

/api/record?key=yourkey

curl能够返回api相关信息则服务运行正常。后续用户使用中IP发生变化时,需要更新订阅链接。所以推荐用户打开自动更新订阅功能。