使用Docker部署Trojan-go

我使用的服务器系统是Ubuntu 20.04 - x86_64,使用root用户操作。关于Trojan-go你可以在这里获得详细信息。

安装Docker

apt install apt-transport-https ca-certificates curl software-properties-common

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -

add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"

apt update && apt install docker-ce

安装acme.sh签发证书

curl https://get.acme.sh | sh -s email=email@your-domain-name.com
alias acme.sh=~/.acme.sh/acme.sh

我使用Cloudflare管理域名,所以直接用Cloudflare来验证域名DNS的方式签发证书。

export CF_Key="Global API Key"
export CF_Email="Cloudflare Email Address"

签发域名证书

acme.sh --issue --dns dns_cf -d your-domain-name.com -k ec-256

配置运行Trojan-go

$ mkdir -p /etc/trojan-go

$ cat > /etc/trojan-go/config.json <<EOF
{
    "run_type": "server",
    "local_addr": "0.0.0.0",
    "local_port": 9527,
    "remote_addr": "127.0.0.1",
    "remote_port": 80,
    "password": [
        "your_awesome_password"
    ],
    "ssl": {
        "cert": "/etc/trojan-go/server.cer",
        "key": "/etc/trojan-go/server.key",
        "sni": "your-domain-name.com"
    }
}
EOF

安装证书到指定位置

acme.sh --installcert -d your-domain-name.com --fullchain-file /etc/trojan-go/server.cer --key-file /etc/trojan-go/server.key --ecc

运行Trojan-go

docker run -d --network host --name trojan-go --restart=always -v /etc/trojan-go:/etc/trojan-go teddysun/trojan-go

查看Trojan-go运行日志

docker logs trojan-go

开启Docker开机自启

systemctl enable docker.service