前提条件:

  1. 一台外网云服务器
  2. 域名
  3. https 证书

服务端安装 trojan

切换到 root 身份:sudo su

1
bash -c "$(curl -fsSL https://raw.githubusercontent.com/trojan-gfw/trojan-quickstart/master/trojan-quickstart.sh)"

安装提示:

Entering temp directory /tmp/tmp.3t5aPoYDpj...
Downloading trojan 1.16.0...
################################################################################################################################################### 100.0%
Unpacking trojan 1.16.0...
Installing trojan 1.16.0 to /usr/local/bin/trojan...
Installing trojan server config to /usr/local/etc/trojan/config.json...
Installing trojan systemd service to /etc/systemd/system/trojan.service...
Reloading systemd daemon...
Deleting temp directory /tmp/tmp.3t5aPoYDpj...
Done!

配置文档说明:https://trojan-gfw.github.io/trojan/config

修改配置

  1. server.json 服务器配置
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
{
    "run_type": "server",
    "local_addr": "0.0.0.0",
    "local_port": 443,
    "remote_addr": "127.0.0.1",
    "remote_port": 80,
    "password": [
        "1qaz2~!+Z"
    ],
    "log_level": 1,
    "ssl": {
        "cert": "/usr/local/etc/trojan/aws.com.cn_bundle.crt",
        "key": "/usr/local/etc/trojan/aws.com.cn.key",
        "key_password": "",
        "cipher": "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384",
        "cipher_tls13": "TLS_AES_128_GCM_SHA256:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_256_GCM_SHA384",
        "prefer_server_cipher": true,
        "alpn": [
            "http/1.1"
        ],
        "alpn_port_override": {
            "h2": 81
        },
        "reuse_session": true,
        "session_ticket": false,
        "session_timeout": 600,
        "plain_http_response": "",
        "curves": "",
        "dhparam": ""
    },
    "tcp": {
        "prefer_ipv4": false,
        "no_delay": true,
        "keep_alive": true,
        "reuse_port": false,
        "fast_open": false,
        "fast_open_qlen": 20
    },
    "mysql": {
        "enabled": false,
        "server_addr": "127.0.0.1",
        "server_port": 3306,
        "database": "trojan",
        "username": "trojan",
        "password": "",
        "key": "",
        "cert": "",
        "ca": ""
    }
}

运行 trojan,指定运行配置 config.json

trojan -c /usr/local/etc/trojan/config.json

修改 trojan 系统服务配置 nano /etc/systemd/system/trojan.service

检查 trojan 启动服务状态 systemctl status trojan

修改服务权限 sudo chmod 644 /etc/systemd/system/trojan.service

sudo systemctl daemon-reload

查看运行日志 journalctl -u trojan -xe

Windows 客户端 V2Ray

客户端使用 v2rayN ,下载地址:https://github.com/2dust/v2rayN/releases/