trojan-go
Support CDN like Cloudflare to hide your server's IP, or use it even if it's blocked.
download
https://github.com/p4gefau1t/trojan-go/releases
mkdir trojan-go && cd trojan-go
wget https://github.com/p4gefau1t/trojan-go/releases/download/v0.10.6/trojan-go-linux-amd64.zip
unzip trojan-go-linux-amd64.zipbash
Cloudflare settings
Go to SSL/TLS:
-
set
Overview --> Encryption modetoFull. -
Origin server --> Origin Certificates --> Create Certificate.Copy and paste your
cert.pem & private.key! Put them on your server, like under/root/cert/.
Go to DNS:
- add a new A record that parse your domain name to your server IP.
- make sure to use
Proxied.
server
A config example:
{
"run_type": "server",
"local_addr": "0.0.0.0",
"local_port": 443,
"remote_addr": "127.0.0.1",
"remote_port": 80,
"log_level": 2,
"log_file": "",
"password": [
"your_password" // NEED MODIFICATION
],
"disable_http_check": false,
"udp_timeout": 60,
"ssl": {
"verify": true,
"verify_hostname": true,
"cert": "/root/cert/cert.pem", // NEED MODIFICATION
"key": "/root/cert/private.key", // NEED MODIFICATION
"key_password": "",
"cipher": "",
"curves": "",
"prefer_server_cipher": false,
"sni": "your_domain_name", // NEED MODIFICATION
"alpn": [
"h2"
],
"session_ticket": true,
"reuse_session": true,
"plain_http_response": "",
"fallback_addr": "",
"fallback_port": 0,
"fingerprint": "firefox"
},
"tcp": {
"no_delay": true,
"keep_alive": true,
"prefer_ipv4": true
},
"mux": {
"enabled": true,
"concurrency": 64,
"idle_timeout": 60
},
"websocket": {
"enabled": true, // true if you want to use it behind CDN
"path": "/websocket", // should be the same as client
"host": "your_domain_name" // should be the same to SNI
},
"shadowsocks": {
"enabled": false,
"method": "AES-128-GCM",
"password": ""
}
}json
Enable as a system service:
# edit it to make sure the path to trojan-go and config exists.
# change User to root if permission denied.
vim trojan-go/examples/trojan-go.service
# enable systemd service
cp trojan-go/examples/trojan-go.service /etc/systemd/system/
systemctl enable trojan-go
systemctl start trojan-go
systemctl statue trojan-gobash
This will make trojan handle 443 port, but you still need to host NGINX at 80 to accept non-trojan requests with a simple config like:
server {
listen80; # must enable http/2
server_name; # match all
location {
proxy_pass;
}
}nginx
To reuse 443 via NGINX streaming, first change trojan config:
{
"local_addr": "127.0.0.1",
"local_port": 10241,
"remote_addr": "127.0.0.1",
"remote_port": 10242,
}json
then host NGINX yourself with config like:
user;
worker_processes;
pid;
# include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections768;
# multi_accept on;
}
### reuse 443 port
stream {
map$ssl_preread_server_name$backend_name {
kiui.moe;
www.kiui.moe;
trojan.kiui.moe;
default;
}
upstream {
server;
}
upstream {
server; ### trojan local_port
}
server {
listen443;
listen;
proxy_pass$backend_name;
ssl_prereadon;
}
}
http {
### for websocket
map$http_upgrade$connection_upgrade {
default;
'' close;
}
sendfileon;
tcp_nopushon;
tcp_nodelayon;
keepalive_timeout65;
types_hash_max_size2048;
include;
default_type;
access_log;
error_log;
gzipon;
### trojan http --> https
server {
listen80;
listen;
server_name;
return301$request_uri;
}
### trojan remote_port
server {
listen10242; # must enable http/2
server_name; # match all
location {
#proxy_pass https://bilibili.com;
proxy_pass; # redirect to web https
}
}
### web http & https
server {
listen80;
listen;
listen10240; # enable ssl
listen;
server_name;
ssl_certificate; # path to your ssl cert
ssl_certificate_key;
ssl_session_timeout5m;
ssl_ciphers;
ssl_protocols;
ssl_prefer_server_cipherson;
location {
root;
}
}
}nginx
restart NGINX:
systemctl restart nginx
systemctl status nginxbash
Client
trojan-go client
a config:
{
"run_type": "client",
"local_addr": "0.0.0.0",
"local_port": 1080,
"remote_addr": "your_domain_name", // NEED MODIFICATION
"remote_port": 443,
"log_level": 2,
"log_file": "",
"password": [
"your_password" // NEED MODIFICATION
],
"disable_http_check": false,
"udp_timeout": 60,
"ssl": {
"verify": true,
"verify_hostname": true,
"cert": "", // NEED MODIFICATION
"key": "", // NEED MODIFICATION
"key_password": "",
"cipher": "",
"curves": "",
"prefer_server_cipher": false,
"sni": "your_domain_name", // NEED MODIFICATION
"alpn": [
"h2"
],
"session_ticket": true,
"reuse_session": true,
"plain_http_response": "",
"fallback_addr": "",
"fallback_port": 0,
"fingerprint": "firefox"
},
"tcp": {
"no_delay": true,
"keep_alive": true,
"prefer_ipv4": true
},
"mux": {
"enabled": true,
"concurrency": 64,
"idle_timeout": 60
},
"websocket": {
"enabled": true, // true if you want to use it behind CDN
"path": "/websocket", // should be the same as server
"host": "your_domain_name" // should be the same to SNI
},
"shadowsocks": {
"enabled": false,
"method": "AES-128-GCM",
"password": ""
}
}json
also start it via systemd:
# edit it to make sure the path to trojan-go and config exists.
# change User to root if permission denied.
vim trojan-go/examples/trojan-go.service
# enable systemd service
cp trojan-go/examples/trojan-go.service /etc/systemd/system/
systemctl enable trojan-go
systemctl start trojan-go
systemctl statue trojan-gobash
Clash client (recommended)
get clash:
wget https://github.com/Dreamacro/clash/releases/download/v1.16.0/clash-linux-amd64-v1.16.0.gz
gz -d clash-linux-amd64-v1.16.0.gz
mv clash-linux-amd64-v1.16.0 clash
chmod 777 clash
# manually get Country.mmdb if automatical download failed
wget https://github.com/Dreamacro/maxmind-geoip/releases/download/20230512/Country.mmdbbash
config like:
proxies:
- name: your_trojan_proxy
type: trojan
server: trojan.kiui.moe
port: 443
password: your_password
network: ws
sni: trojan.kiui.moe
# udp: true
# skip-cert-verify: true
ws-opts:
path: /websocket
headers:
Host: trojan.kiui.moeyaml
make it a service under /etc/systemd/system/clash.service: (MODIFY the paths!)
[Unit]
Description=Clash daemon, A rule-based proxy in Go.
After=network-online.target
[Service]
Type=simple
Restart=always
ExecStart=/path/to/clash -d /path/to/workspace -f /path/to/config
[Install]
WantedBy=multi-user.target
enable it:
systemctl enable clash
systemctl start clashbash
finally, set up system proxy to manual and enter your http/socks5 port.