mirror of
https://github.com/p4gefau1t/trojan-go.git
synced 2024-04-21 12:21:34 +00:00
204 lines
15 KiB
HTML
204 lines
15 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="zh-CN">
|
||
<head><meta charset="utf-8">
|
||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
|
||
<title>正确配置Trojan-Go - Trojan-Go Docs</title>
|
||
<meta name="description" content="An unidentifiable mechanism that helps you bypass GFW.">
|
||
<meta name="generator" content="Hugo 0.69.2" />
|
||
<link href="https://p4gefau1t.github.io/trojan-goindex.xml" rel="alternate" type="application/rss+xml">
|
||
<link rel="canonical" href="https://p4gefau1t.github.io/trojan-go/basic/config/">
|
||
<link rel="stylesheet" href="https://p4gefau1t.github.io/trojan-go/css/theme.min.css">
|
||
<script src="https://use.fontawesome.com/releases/v5.0.6/js/all.js"></script>
|
||
<link rel="stylesheet" href="https://p4gefau1t.github.io/trojan-go/css/chroma.min.css">
|
||
<script src="https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.min.js"></script>
|
||
<script src="https://cdn.jsdelivr.net/npm/jquery.easing@1.4.1/jquery.easing.min.js"></script>
|
||
<script src="https://p4gefau1t.github.io/trojan-go/js/bundle.js"></script><style>
|
||
:root {}
|
||
</style>
|
||
<meta property="og:title" content="正确配置Trojan-Go" />
|
||
<meta property="og:description" content="下面将介绍如何正确配置Trojan-Go以完全隐藏你的代理节点特征。 在开始之前,你需要 一个服务器,且未被GFW封锁 一个域名,可以使用免费的域" />
|
||
<meta property="og:type" content="article" />
|
||
<meta property="og:url" content="https://p4gefau1t.github.io/trojan-go/basic/config/" />
|
||
<meta property="og:image" content="https://p4gefau1t.github.io/trojan-go/images/og-image.png"/>
|
||
<meta property="og:site_name" content="Trojan-Go Docs" />
|
||
<meta name="twitter:card" content="summary_large_image"/>
|
||
<meta name="twitter:image" content="https://p4gefau1t.github.io/trojan-go/images/og-image.png"/>
|
||
|
||
<meta name="twitter:title" content="正确配置Trojan-Go"/>
|
||
<meta name="twitter:description" content="下面将介绍如何正确配置Trojan-Go以完全隐藏你的代理节点特征。 在开始之前,你需要 一个服务器,且未被GFW封锁 一个域名,可以使用免费的域"/>
|
||
<meta itemprop="name" content="正确配置Trojan-Go">
|
||
<meta itemprop="description" content="下面将介绍如何正确配置Trojan-Go以完全隐藏你的代理节点特征。 在开始之前,你需要 一个服务器,且未被GFW封锁 一个域名,可以使用免费的域">
|
||
|
||
<meta itemprop="wordCount" content="2029">
|
||
<meta itemprop="image" content="https://p4gefau1t.github.io/trojan-go/images/og-image.png"/>
|
||
|
||
|
||
|
||
<meta itemprop="keywords" content="" /></head>
|
||
<body><div class="container"><header>
|
||
<h1>Trojan-Go Docs</h1>
|
||
<a href="https://github.com/p4gefau1t/trojan-go" class="github"><i class="fab fa-github"></i></a>
|
||
<p class="description">An unidentifiable mechanism that helps you bypass GFW.</p>
|
||
|
||
</header>
|
||
<div class="global-menu">
|
||
<nav>
|
||
<ul>
|
||
<li><a href="/trojan-go/">Home</a></li>
|
||
<li><a href="https://github.com/p4gefau1t">GitHub</a></li></ul>
|
||
</nav>
|
||
</div>
|
||
<div class="content-container">
|
||
<main><h1>正确配置Trojan-Go</h1>
|
||
<p>下面将介绍如何正确配置Trojan-Go以完全隐藏你的代理节点特征。</p>
|
||
<p>在开始之前,你需要</p>
|
||
<ul>
|
||
<li>
|
||
<p>一个服务器,且未被GFW封锁</p>
|
||
</li>
|
||
<li>
|
||
<p>一个域名,可以使用免费的域名服务,如.tk等</p>
|
||
</li>
|
||
<li>
|
||
<p>Trojan-Go,可以从release页面下载</p>
|
||
</li>
|
||
<li>
|
||
<p>证书和密钥,可以从letsencrpyt等机构免费申请签发</p>
|
||
</li>
|
||
</ul>
|
||
<h3 id="服务端配置">服务端配置</h3>
|
||
<p>我们的目标是,使得你的服务器和正常的HTTPS网站表现相同。</p>
|
||
<p>首先你需要一个HTTP服务器,可以使用nginx,apache,caddy等配置一个本地HTTP服务器,也可以使用别人的HTTP服务器。HTTP服务器的作用是,当GFW主动探测时,向它展示一个完全正常的Web页面。</p>
|
||
<p><strong>你需要在<code>remote_addr</code>和<code>remote_port</code>指定这个HTTP服务器的地址。<code>remote_addr</code>可以是IP或者域名。Trojan-Go将会测试这个HTTP服务器是否工作正常,如果不正常,Trojan-Go会拒绝启动。</strong></p>
|
||
<p>下面是一份比较安全的服务器配置server.json,需要你在本地80端口配置一个HTTP服务(必要,你也可以使用其他的网站HTTP服务器,如"remote_addr”: “example.com”),在1234端口配置一个HTTPS服务,或是一个展示"400 Bad Request"的静态HTTP网页服务。(可选,可以删除<code>fallback_port</code>字段,跳过这个步骤)</p>
|
||
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-json" data-lang="json">{
|
||
<span style="color:#f92672">"run_type"</span>: <span style="color:#e6db74">"server"</span>,
|
||
<span style="color:#f92672">"local_addr"</span>: <span style="color:#e6db74">"0.0.0.0"</span>,
|
||
<span style="color:#f92672">"local_port"</span>: <span style="color:#ae81ff">443</span>,
|
||
<span style="color:#f92672">"remote_addr"</span>: <span style="color:#e6db74">"127.0.0.1"</span>,
|
||
<span style="color:#f92672">"remote_port"</span>: <span style="color:#ae81ff">80</span>,
|
||
<span style="color:#f92672">"password"</span>: [
|
||
<span style="color:#e6db74">"your_awesome_password"</span>
|
||
],
|
||
<span style="color:#f92672">"ssl"</span>: {
|
||
<span style="color:#f92672">"cert"</span>: <span style="color:#e6db74">"server.crt"</span>,
|
||
<span style="color:#f92672">"key"</span>: <span style="color:#e6db74">"server.key"</span>,
|
||
<span style="color:#f92672">"fallback_port"</span>: <span style="color:#ae81ff">1234</span>
|
||
}
|
||
}
|
||
</code></pre></div><p>这个配置文件使Trojan-Go在服务器的所有IP地址上(0.0.0.0)监听443端口,分别使用server.crt和server.key作为证书和密钥进行TLS握手。你应该使用尽可能复杂的密码,同时确保客户端和服务端<code>password</code>是一致的。注意,<strong>Trojan-Go会检测你的HTTP服务器<code>http://remote_addr:remote_port</code>是否正常工作。如果你的HTTP服务器工作不正常,Trojan-Go将拒绝启动。</strong></p>
|
||
<p>当一个客户端试图连接Trojan-Go的监听端口时,会发生下面的事情:</p>
|
||
<ul>
|
||
<li>
|
||
<p>如果TLS握手成功,检测到TLS的内容非Trojan协议(有可能是HTTP请求,或者来自GFW的主动探测)。Trojan-Go将TLS连接代理到本地127.0.0.1:80上的HTTP服务。这时在远端看来,Trojan-Go服务就是一个HTTPS网站。</p>
|
||
</li>
|
||
<li>
|
||
<p>如果TLS握手成功,并且被确认是Trojan协议头部,并且其中的密码正确,那么服务器将解析来自客户端的请求并进行代理,否则和上一步的处理方法相同。</p>
|
||
</li>
|
||
<li>
|
||
<p>如果TLS握手失败,说明对方使用的不是TLS协议进行连接。此时Trojan-Go将这个TCP连接代理到本地127.0.0.1:1234上运行的HTTPS服务(或者HTTP服务),返回一个展示400 Bad Reqeust的HTTP页面。<code>fallback_port</code>是一个可选选项,如果没有填写,Trojan-Go会直接终止连接。虽然是可选的,但是还是强烈建议填写。</p>
|
||
</li>
|
||
</ul>
|
||
<p>你可以通过使用浏览器访问你的域名<code>https://your-domain-name.com</code>来验证。如果工作正常,你的浏览器会显示一个正常的HTTPS保护的Web页面,页面内容与服务器本机80端口上的页面一致。你还可以使用<code>http://your-domain-name.com:443</code>验证<code>fallback_port</code>工作是否正常。</p>
|
||
<p>事实上,你甚至可以将Trojan-Go当作你的HTTPS服务器,用来给你的网站提供HTTPS服务。访客可以正常地通过Trojan-Go浏览你的网站,而和代理流量互不影响。但是注意,不要在<code>remote_port</code>和<code>fallback_port</code>搭建有高实时性需求的服务,Trojan-Go识别到非Trojan协议流量时会有意增加少许延迟以抵抗GFW基于时间的检测。</p>
|
||
<p>配置完成后,可以使用</p>
|
||
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">./trojan-go -config ./server.json
|
||
</code></pre></div><p>启动服务端。</p>
|
||
<h3 id="客户端配置">客户端配置</h3>
|
||
<p>对应的客户端配置client.json</p>
|
||
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-json" data-lang="json">{
|
||
<span style="color:#f92672">"run_type"</span>: <span style="color:#e6db74">"client"</span>,
|
||
<span style="color:#f92672">"local_addr"</span>: <span style="color:#e6db74">"127.0.0.1"</span>,
|
||
<span style="color:#f92672">"local_port"</span>: <span style="color:#ae81ff">1080</span>,
|
||
<span style="color:#f92672">"remote_addr"</span>: <span style="color:#e6db74">"your_awesome_server"</span>,
|
||
<span style="color:#f92672">"remote_port"</span>: <span style="color:#ae81ff">443</span>,
|
||
<span style="color:#f92672">"password"</span>: [
|
||
<span style="color:#e6db74">"your_awesome_password"</span>
|
||
],
|
||
<span style="color:#f92672">"ssl"</span>: {
|
||
<span style="color:#f92672">"sni"</span>: <span style="color:#e6db74">"your-domain-name.com"</span>
|
||
}
|
||
}
|
||
</code></pre></div><p>这个客户端配置使Trojan-Go开启一个监听在本地1080端口的socks5/http代理(自动识别),远端服务器为your_awesome_server:443,your_awesome_server可以是IP或者域名。</p>
|
||
<p>如果你在<code>remote_addr</code>中填写的是域名,<code>sni</code>可以省略。如果你在<code>remote_addr</code>填写的是IP地址,<code>sni</code>字段应当填写你申请证书的对应域名,或者你自己签发的证书的Common Name,而且必须一致。注意,<code>sni</code>字段目前的在TLS协议中是<strong>明文传送</strong>的(目的是使服务器提供相应证书)。GFW已经被证实具有SNI探测和阻断能力,所以不要填写类似<code>google.com</code>等已经被封锁的域名,否则很有可能导致你的服务器也被遭到封锁。</p>
|
||
<p>配置完成后,可以使用</p>
|
||
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">./trojan-go -config ./client.json
|
||
</code></pre></div><p>启动客户端。</p>
|
||
<p>更多关于配置文件的信息,可以在左侧导航栏中找到相应介绍。</p>
|
||
<div class="edit-meta">
|
||
|
||
<br><a href="https://github.com/p4gefau1t/trojan-go/docs/edit/master/content/basic/config.md" class="edit-page"><i class="fas fa-pen-square"></i> Edit on GitHub</a></div><nav class="pagination"><a class="nav nav-prev" href="https://p4gefau1t.github.io/trojan-go/basic/trojan/" title="Trojan基本原理"><i class="fas fa-arrow-left" aria-hidden="true"></i> Prev - Trojan基本原理</a>
|
||
<a class="nav nav-next" href="https://p4gefau1t.github.io/trojan-go/basic/full-config/" title="完整的配置文件">Next - 完整的配置文件 <i class="fas fa-arrow-right" aria-hidden="true"></i></a>
|
||
</nav><footer><p class="powered">Powered by <a href="https://gohugo.io">Hugo</a>. Theme by <a href="https://themes.gohugo.io/hugo-theme-techdoc/">TechDoc</a>. Designed by <a href="https://github.com/thingsym/hugo-theme-techdoc">Thingsym</a>.</p>
|
||
</footer>
|
||
</main><div class="sidebar">
|
||
|
||
<nav class="open-menu">
|
||
<ul>
|
||
<li class=""><a href="https://p4gefau1t.github.io/trojan-go">Home</a></li>
|
||
|
||
<li class="parent"><a href="https://p4gefau1t.github.io/trojan-go/basic/">基本配置</a>
|
||
|
||
<ul class="sub-menu">
|
||
<li class=""><a href="https://p4gefau1t.github.io/trojan-go/basic/trojan/">Trojan基本原理</a></li>
|
||
<li class="active"><a href="https://p4gefau1t.github.io/trojan-go/basic/config/">正确配置Trojan-Go</a></li>
|
||
<li class=""><a href="https://p4gefau1t.github.io/trojan-go/basic/full-config/">完整的配置文件</a></li>
|
||
</ul>
|
||
|
||
</li>
|
||
|
||
<li class=""><a href="https://p4gefau1t.github.io/trojan-go/advance/">高级配置</a>
|
||
|
||
<ul class="sub-menu">
|
||
<li class=""><a href="https://p4gefau1t.github.io/trojan-go/advance/mux/">启用多路复用提升网络并发性能</a></li>
|
||
<li class=""><a href="https://p4gefau1t.github.io/trojan-go/advance/websocket/">使用Websocket进行CDN转发和抵抗中间人攻击</a></li>
|
||
<li class=""><a href="https://p4gefau1t.github.io/trojan-go/advance/router/">国内直连和广告屏蔽</a></li>
|
||
<li class=""><a href="https://p4gefau1t.github.io/trojan-go/advance/forward/">隧道和反向代理</a></li>
|
||
<li class=""><a href="https://p4gefau1t.github.io/trojan-go/advance/nginx-relay/">一种基于SNI代理的多路径分流中继方案</a></li>
|
||
<li class=""><a href="https://p4gefau1t.github.io/trojan-go/advance/plugin/">使用Shadowsocks插件/可插拔传输层</a></li>
|
||
<li class=""><a href="https://p4gefau1t.github.io/trojan-go/advance/aead/">使用Shadowsocks AEAD进行二次加密</a></li>
|
||
<li class=""><a href="https://p4gefau1t.github.io/trojan-go/advance/customize-protocol-stack/">自定义协议栈</a></li>
|
||
<li class=""><a href="https://p4gefau1t.github.io/trojan-go/advance/api/">使用API动态管理用户</a></li>
|
||
<li class=""><a href="https://p4gefau1t.github.io/trojan-go/advance/nat/">透明代理</a></li>
|
||
</ul>
|
||
|
||
</li>
|
||
|
||
<li class=""><a href="https://p4gefau1t.github.io/trojan-go/developer/">实现细节和开发指南</a>
|
||
|
||
<ul class="sub-menu">
|
||
<li class=""><a href="https://p4gefau1t.github.io/trojan-go/developer/overview/">基本介绍</a></li>
|
||
<li class=""><a href="https://p4gefau1t.github.io/trojan-go/developer/build/">编译和自定义Trojan-Go</a></li>
|
||
<li class=""><a href="https://p4gefau1t.github.io/trojan-go/developer/trojan/">Trojan协议</a></li>
|
||
<li class=""><a href="https://p4gefau1t.github.io/trojan-go/developer/mux/">多路复用</a></li>
|
||
<li class=""><a href="https://p4gefau1t.github.io/trojan-go/developer/websocket/">Websocket</a></li>
|
||
<li class=""><a href="https://p4gefau1t.github.io/trojan-go/developer/simplesocks/">SimpleSocks协议</a></li>
|
||
<li class=""><a href="https://p4gefau1t.github.io/trojan-go/developer/api/">API开发</a></li>
|
||
<li class=""><a href="https://p4gefau1t.github.io/trojan-go/developer/plugin/">可插拔传输层插件开发</a></li>
|
||
<li class=""><a href="https://p4gefau1t.github.io/trojan-go/developer/url/">URL方案(草案)</a></li>
|
||
</ul>
|
||
|
||
</li>
|
||
</ul>
|
||
</nav>
|
||
|
||
|
||
|
||
<div class="sidebar-footer"></div>
|
||
</div>
|
||
</div><a href="#" id="backtothetop-fixed" class="backtothetop"
|
||
data-backtothetop-duration="600"
|
||
data-backtothetop-easing="easeOutQuart"
|
||
data-backtothetop-fixed-fadeIn="1000"
|
||
data-backtothetop-fixed-fadeOut="1000"
|
||
data-backtothetop-fixed-bottom="10"
|
||
data-backtothetop-fixed-right="20">
|
||
<span class="fa-layers fa-fw">
|
||
<i class="fas fa-circle"></i>
|
||
<i class="fas fa-arrow-circle-up"></i>
|
||
</span></a>
|
||
</div>
|
||
</body>
|
||
</html>
|