找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 6051|回复: 0

内网穿透工具 FRP 使用实例

[复制链接]
发表于 2022-9-16 17:31:28 | 显示全部楼层 |阅读模式
<div><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">下面我们就来看几个常用的例子,通过这些例子来了解下 FRP 是如何实现内网服务穿透的。</p><h2 style="margin: 20px -20px 20px -24px; color: rgb(85, 85, 85); font-weight: 400; font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; line-height: 18px; text-rendering: optimizelegibility; font-size: 18px; padding: 10px 20px 9px; border-left: 4px solid rgb(66, 139, 202); background-color: rgb(251, 251, 251);">身份验证</h2><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">服务端和客户端的 <span style="font-weight: 700;">common</span> 配置中的 <span style="font-weight: 700;">token</span> 参数一致则身份验证通过。</p><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;"><span style="color: rgb(255, 0, 0);">公网</span>服务端 <span style="font-weight: 700;">frp<span style="color: rgb(255, 0, 0);">s</span>&#46;ini</span> 配置文件、<span style="color: rgb(0, 0, 255);">内网</span>客户端 <span style="font-weight: 700;">frp<span style="color: rgb(0, 0, 255);">c</span>&#46;ini</span> 配置文件</p><div class="code-toolbar" style="position: relative; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;"><pre class=" language-ini" style="padding: 1em; border-radius: 0&#46;3em; color: rgb(248, 248, 242); font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 12px; line-height: 1&#46;5; font-family: Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace; margin-top: 0&#46;5em; margin-bottom: 0&#46;5em; border-style: solid; border-color: rgb(230, 230, 230); background-color: rgb(39, 40, 34); overflow-wrap: normal; word-break: normal; text-shadow: rgba(0, 0, 0, 0&#46;3) 0px 1px; word-spacing: normal; tab-size: 4; hyphens: none; overflow: auto;"><code class=" language-ini" style="padding: 0px; border-radius: 3px; font-size: 10px; font-family: Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace; border: 0px; background: none; text-shadow: rgba(0, 0, 0, 0&#46;3) 0px 1px; word-spacing: normal; word-break: normal; overflow-wrap: normal; line-height: 1&#46;5; tab-size: 4; hyphens: none;">[common]
token = www&#46;nasge&#46;com</code></pre><div class="toolbar" style="position: absolute; top: 0&#46;3em; right: 0&#46;2em; transition: opacity 0&#46;3s ease-in-out 0s; opacity: 0;"><div class="toolbar-item" style="display: inline-block;"><span style="color: rgb(187, 187, 187); font-size: 0&#46;8em; padding: 0px 0&#46;5em; background: rgba(224, 224, 224, 0&#46;2); box-shadow: rgba(0, 0, 0, 0&#46;2) 0px 2px 0px 0px; border-radius: 0&#46;5em;">Ini</span></div><div class="toolbar-item" style="display: inline-block;"><a style="color: rgb(187, 187, 187); cursor: pointer; font-size: 0&#46;8em; padding: 0px 0&#46;5em; background: rgba(224, 224, 224, 0&#46;2); box-shadow: rgba(0, 0, 0, 0&#46;2) 0px 2px 0px 0px; border-radius: 0&#46;5em;">Copy</a></div></div></div><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;"> </p><h2 style="margin: 20px -20px 20px -24px; color: rgb(85, 85, 85); font-weight: 400; font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; line-height: 18px; text-rendering: optimizelegibility; font-size: 18px; padding: 10px 20px 9px; border-left: 4px solid rgb(66, 139, 202); background-color: rgb(251, 251, 251);">通过 TCP 访问内网机器</h2><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">这里以访问 SSH 服务为例,Linux系统环境下设置</p><h3 style="margin: 5px 0px 20px; color: rgb(85, 85, 85); font-weight: 400; font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; line-height: 25px; text-rendering: optimizelegibility; font-size: 16px; padding-bottom: 5px; border-bottom: 1px solid rgb(238, 238, 238);"><span style="color: rgb(255, 0, 0);">公网</span>服务端配置</h3><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">首先修改 FRP 公网服务端 <span style="font-weight: 700;">frp<span style="color: rgb(255, 0, 0);">s</span>&#46;ini</span> 配置文件,默认文件无需修改,直接下一步使用命令启动 frps 服务端</p><div class="code-toolbar" style="position: relative; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;"><pre class=" language-ini" style="padding: 1em; border-radius: 0&#46;3em; color: rgb(248, 248, 242); font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 12px; line-height: 1&#46;5; font-family: Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace; margin-top: 0&#46;5em; margin-bottom: 0&#46;5em; border-style: solid; border-color: rgb(230, 230, 230); background-color: rgb(39, 40, 34); overflow-wrap: normal; word-break: normal; text-shadow: rgba(0, 0, 0, 0&#46;3) 0px 1px; word-spacing: normal; tab-size: 4; hyphens: none; overflow: auto;"><code class=" language-ini" style="padding: 0px; border-radius: 3px; font-size: 10px; font-family: Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace; border: 0px; background: none; text-shadow: rgba(0, 0, 0, 0&#46;3) 0px 1px; word-spacing: normal; word-break: normal; overflow-wrap: normal; line-height: 1&#46;5; tab-size: 4; hyphens: none;">root@U-NAS:~/frp# vi frps&#46;ini
# frps&#46;ini 内容
[common]
bind_port = 7000</code></pre><div class="toolbar" style="position: absolute; top: 0&#46;3em; right: 0&#46;2em; transition: opacity 0&#46;3s ease-in-out 0s; opacity: 0;"><div class="toolbar-item" style="display: inline-block;"><span style="color: rgb(187, 187, 187); font-size: 0&#46;8em; padding: 0px 0&#46;5em; background: rgba(224, 224, 224, 0&#46;2); box-shadow: rgba(0, 0, 0, 0&#46;2) 0px 2px 0px 0px; border-radius: 0&#46;5em;">Ini</span></div><div class="toolbar-item" style="display: inline-block;"><a style="color: rgb(187, 187, 187); cursor: pointer; font-size: 0&#46;8em; padding: 0px 0&#46;5em; background: rgba(224, 224, 224, 0&#46;2); box-shadow: rgba(0, 0, 0, 0&#46;2) 0px 2px 0px 0px; border-radius: 0&#46;5em;">Copy</a></div></div></div><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">在frp目录下输入【<span style="color: rgb(255, 0, 0);">&#46;/frps -c &#46;/frps&#46;ini</span>】命令启动 frps</p><div class="code-toolbar" style="position: relative; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;"><pre class=" language-bash" style="padding: 1em; border-radius: 0&#46;3em; color: rgb(248, 248, 242); font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 12px; line-height: 1&#46;5; font-family: Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace; margin-top: 0&#46;5em; margin-bottom: 0&#46;5em; border-style: solid; border-color: rgb(230, 230, 230); background-color: rgb(39, 40, 34); overflow-wrap: normal; word-break: normal; text-shadow: rgba(0, 0, 0, 0&#46;3) 0px 1px; word-spacing: normal; tab-size: 4; hyphens: none; overflow: auto;"><code class=" language-bash" style="padding: 0px; border-radius: 3px; font-size: 10px; font-family: Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace; border: 0px; background: none; text-shadow: rgba(0, 0, 0, 0&#46;3) 0px 1px; word-spacing: normal; word-break: normal; overflow-wrap: normal; line-height: 1&#46;5; tab-size: 4; hyphens: none;">root@U-NAS:~/frp<span class="token comment" style="padding: 12px 0px 10px; position: relative; margin: 20px 0px; color: slategray;"># &#46;/frps -c &#46;/frps&#46;ini</span>
2019/12/18 13:29:34 <span class="token punctuation">[</span>I<span class="token punctuation">]</span> <span class="token punctuation">[</span>service&#46;go:141<span class="token punctuation">]</span> frps tcp listen on 0&#46;0&#46;0&#46;0:7000
2019/12/18 13:29:34 <span class="token punctuation">[</span>I<span class="token punctuation">]</span> <span class="token punctuation">[</span>root&#46;go:205<span class="token punctuation">]</span> start frps success</code></pre><div class="toolbar" style="position: absolute; top: 0&#46;3em; right: 0&#46;2em; transition: opacity 0&#46;3s ease-in-out 0s; opacity: 0;"><div class="toolbar-item" style="display: inline-block;"><span style="color: rgb(187, 187, 187); font-size: 0&#46;8em; padding: 0px 0&#46;5em; background: rgba(224, 224, 224, 0&#46;2); box-shadow: rgba(0, 0, 0, 0&#46;2) 0px 2px 0px 0px; border-radius: 0&#46;5em;">Bash</span></div><div class="toolbar-item" style="display: inline-block;"><a style="color: rgb(187, 187, 187); cursor: pointer; font-size: 0&#46;8em; padding: 0px 0&#46;5em; background: rgba(224, 224, 224, 0&#46;2); box-shadow: rgba(0, 0, 0, 0&#46;2) 0px 2px 0px 0px; border-radius: 0&#46;5em;">Copy</a></div></div></div><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">出现【<span style="color: rgb(255, 0, 0);">Start frps success</span>】代表运行成功</p><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;"> </p><h3 style="margin: 5px 0px 20px; color: rgb(85, 85, 85); font-weight: 400; font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; line-height: 25px; text-rendering: optimizelegibility; font-size: 16px; padding-bottom: 5px; border-bottom: 1px solid rgb(238, 238, 238);"><span style="color: rgb(0, 0, 255);">内网</span>客户端配置</h3><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">这里以访问 SSH 服务为例, 修改 FRP <span style="color: rgb(0, 0, 255);">内网</span>客户端配置文件 <span style="font-weight: 700;">frp<span style="color: rgb(0, 0, 255);">c</span>&#46;ini</span> 文件内容:</p><div class="code-toolbar" style="position: relative; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;"><pre class=" language-bash" style="padding: 1em; border-radius: 0&#46;3em; color: rgb(248, 248, 242); font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 12px; line-height: 1&#46;5; font-family: Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace; margin-top: 0&#46;5em; margin-bottom: 0&#46;5em; border-style: solid; border-color: rgb(230, 230, 230); background-color: rgb(39, 40, 34); overflow-wrap: normal; word-break: normal; text-shadow: rgba(0, 0, 0, 0&#46;3) 0px 1px; word-spacing: normal; tab-size: 4; hyphens: none; overflow: auto;"><code class=" language-bash" style="padding: 0px; border-radius: 3px; font-size: 10px; font-family: Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace; border: 0px; background: none; text-shadow: rgba(0, 0, 0, 0&#46;3) 0px 1px; word-spacing: normal; word-break: normal; overflow-wrap: normal; line-height: 1&#46;5; tab-size: 4; hyphens: none;">root@U-NAS:~/frp<span class="token comment" style="padding: 12px 0px 10px; position: relative; margin: 20px 0px; color: slategray;"># vi frpc&#46;ini</span>
<span class="token punctuation">[</span>common<span class="token punctuation">]</span>
<span class="token comment" style="padding: 12px 0px 10px; position: relative; margin: 20px 0px; color: slategray;"># server_addr 为 FRP 服务端的公网 IP</span>
server_addr <span class="token operator">=</span> 192&#46;168&#46;44&#46;130
<span class="token comment" style="padding: 12px 0px 10px; position: relative; margin: 20px 0px; color: slategray;"># server_port 为 FRP 服务端监听的端口</span>
server_port <span class="token operator">=</span> 7000
<span class="token punctuation">[</span>ssh<span class="token punctuation">]</span>
<span class="token function" style="color: rgb(230, 219, 116);">type</span> <span class="token operator">=</span> tcp
<span class="token comment" style="padding: 12px 0px 10px; position: relative; margin: 20px 0px; color: slategray;"># local_ip 为 内外客户端IP</span>
local_ip <span class="token operator">=</span> 127&#46;0&#46;0&#46;1
<span class="token comment" style="padding: 12px 0px 10px; position: relative; margin: 20px 0px; color: slategray;"># local_port 为 内外客户端端口</span>
local_port <span class="token operator">=</span> 22
<span class="token comment" style="padding: 12px 0px 10px; position: relative; margin: 20px 0px; color: slategray;"># remote_port 为 公网服务端映射端口</span>
remote_port <span class="token operator">=</span> 6000
<span class="token punctuation">[</span>web<span class="token punctuation">]</span>
<span class="token function" style="color: rgb(230, 219, 116);">type</span> <span class="token operator">=</span> tcp
local_ip <span class="token operator">=</span> 127&#46;0&#46;0&#46;1
local_port <span class="token operator">=</span> 80
remote_port <span class="token operator">=</span> 6001</code></pre><div class="toolbar" style="position: absolute; top: 0&#46;3em; right: 0&#46;2em; transition: opacity 0&#46;3s ease-in-out 0s; opacity: 0;"><div class="toolbar-item" style="display: inline-block;"><span style="color: rgb(187, 187, 187); font-size: 0&#46;8em; padding: 0px 0&#46;5em; background: rgba(224, 224, 224, 0&#46;2); box-shadow: rgba(0, 0, 0, 0&#46;2) 0px 2px 0px 0px; border-radius: 0&#46;5em;">Bash</span></div><div class="toolbar-item" style="display: inline-block;"><a style="color: rgb(187, 187, 187); cursor: pointer; font-size: 0&#46;8em; padding: 0px 0&#46;5em; background: rgba(224, 224, 224, 0&#46;2); box-shadow: rgba(0, 0, 0, 0&#46;2) 0px 2px 0px 0px; border-radius: 0&#46;5em;">Copy</a></div></div></div><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">在frp目录下输入【<span style="color: rgb(0, 0, 255);">&#46;/frpc -c &#46;/frpc&#46;ini</span>】命令启动 <span style="font-weight: 700;">frp<span style="color: rgb(0, 0, 255);">c</span></span></p><div class="code-toolbar" style="position: relative; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;"><pre class=" language-bash" style="padding: 1em; border-radius: 0&#46;3em; color: rgb(248, 248, 242); font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 12px; line-height: 1&#46;5; font-family: Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace; margin-top: 0&#46;5em; margin-bottom: 0&#46;5em; border-style: solid; border-color: rgb(230, 230, 230); background-color: rgb(39, 40, 34); overflow-wrap: normal; word-break: normal; text-shadow: rgba(0, 0, 0, 0&#46;3) 0px 1px; word-spacing: normal; tab-size: 4; hyphens: none; overflow: auto;"><code class=" language-bash" style="padding: 0px; border-radius: 3px; font-size: 10px; font-family: Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace; border: 0px; background: none; text-shadow: rgba(0, 0, 0, 0&#46;3) 0px 1px; word-spacing: normal; word-break: normal; overflow-wrap: normal; line-height: 1&#46;5; tab-size: 4; hyphens: none;">root@U-NAS:~/frp<span class="token comment" style="padding: 12px 0px 10px; position: relative; margin: 20px 0px; color: slategray;"># &#46;/frpc -c &#46;/frpc&#46;ini</span>
2019/12/17 17:33:31 <span class="token punctuation">[</span>I<span class="token punctuation">]</span> <span class="token punctuation">[</span>service&#46;go:249<span class="token punctuation">]</span> <span class="token punctuation">[</span>35481b55cd500a76<span class="token punctuation">]</span> login to server success, get run <span class="token function" style="color: rgb(230, 219, 116);">id</span> <span class="token punctuation">[</span>35481b55cd500a76<span class="token punctuation">]</span>, server udp port <span class="token punctuation">[</span>0<span class="token punctuation">]</span>
2019/12/17 18:33:31 <span class="token punctuation">[</span>I<span class="token punctuation">]</span> <span class="token punctuation">[</span>proxy_manager&#46;go:144<span class="token punctuation">]</span> <span class="token punctuation">[</span>35481b55cd500a76<span class="token punctuation">]</span> proxy added: <span class="token punctuation">[</span>ssh web<span class="token punctuation">]</span>
2019/12/17 18:33:31 <span class="token punctuation">[</span>I<span class="token punctuation">]</span> <span class="token punctuation">[</span>control&#46;go:164<span class="token punctuation">]</span> <span class="token punctuation">[</span>35481b55cd500a76<span class="token punctuation">]</span> <span class="token punctuation">[</span>ssh<span class="token punctuation">]</span> start proxy success
2019/12/17 18:33:31 <span class="token punctuation">[</span>I<span class="token punctuation">]</span> <span class="token punctuation">[</span>control&#46;go:164<span class="token punctuation">]</span> <span class="token punctuation">[</span>35481b55cd500a76<span class="token punctuation">]</span> <span class="token punctuation">[</span>web<span class="token punctuation">]</span> start proxy success</code></pre><div class="toolbar" style="position: absolute; top: 0&#46;3em; right: 0&#46;2em; transition: opacity 0&#46;3s ease-in-out 0s; opacity: 0;"><div class="toolbar-item" style="display: inline-block;"><span style="color: rgb(187, 187, 187); font-size: 0&#46;8em; padding: 0px 0&#46;5em; background: rgba(224, 224, 224, 0&#46;2); box-shadow: rgba(0, 0, 0, 0&#46;2) 0px 2px 0px 0px; border-radius: 0&#46;5em;">Bash</span></div><div class="toolbar-item" style="display: inline-block;"><a style="color: rgb(187, 187, 187); cursor: pointer; font-size: 0&#46;8em; padding: 0px 0&#46;5em; background: rgba(224, 224, 224, 0&#46;2); box-shadow: rgba(0, 0, 0, 0&#46;2) 0px 2px 0px 0px; border-radius: 0&#46;5em;">Copy</a></div></div></div><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">这样就可以成功在 FRP <span style="color: rgb(255, 0, 0);">公网</span>服务端上成功建立一个<span style="color: rgb(0, 0, 255);">内网</span>客户端连接,在 FRP 服务端上成功注册了一个端口为 <span style="font-weight: 700;">6000</span>、<span style="font-weight: 700;">6001</span> 的服务,接下来我们就可以通过这两个端口访问<span style="color: rgb(0, 0, 255);">内网</span>客户端上 SSH <span style="font-weight: 700;">22</span>端口、WEB:<span style="font-weight: 700;">80</span>端口服务。</p><ul style="margin: 0px 0px 16px 26px; padding: 0px; list-style: none; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;"><li style="line-height: 20px; margin-bottom: 10px; padding-left: 20px;"><span style="color: rgb(255, 0, 0);">公网</span>服务端 <span style="color: rgb(255, 0, 0);">192&#46;168&#46;44&#46;130</span>:<span style="font-weight: 700;">6000</span> 定向为 <span style="color: rgb(0, 0, 255);">内网</span>客户端 <span style="color: rgb(0, 0, 255);">127&#46;0&#46;0&#46;1</span>:<span style="font-weight: 700;">22</span>【SSH端口】</li><li style="line-height: 20px; margin-bottom: 10px; padding-left: 20px;"><span style="color: rgb(255, 0, 0);">公网</span>服务端 <span style="color: rgb(255, 0, 0);">192&#46;168&#46;44&#46;130</span>:<span style="font-weight: 700;">6001</span> 定向为 <span style="color: rgb(0, 0, 255);">内网</span>客户端 <span style="color: rgb(0, 0, 255);">127&#46;0&#46;0&#46;1</span>:<span style="font-weight: 700;">80</span>【WEB端口】</li></ul><h2 style="margin: 20px -20px 20px -24px; color: rgb(85, 85, 85); font-weight: 400; font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; line-height: 18px; text-rendering: optimizelegibility; font-size: 18px; padding: 10px 20px 9px; border-left: 4px solid rgb(66, 139, 202); background-color: rgb(251, 251, 251);">通过自定义域名访问部署于<span style="color: rgb(0, 0, 255);">内网</span>的 Web 服务</h2><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">有时需要在公有网络通过域名访问我们在本地<span style="color: rgb(0, 0, 255);">内网</span>环境搭建的 Web 服务,但是由于本地环境机器并没有<span style="color: rgb(255, 0, 0);">公网</span> IP,无法将域名直接解析到本地的机器。</p><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">现在通过 FRP 就可以很容易实现这一功能,这里以 HTTP 服务为例</p><h3 style="margin: 5px 0px 20px; color: rgb(85, 85, 85); font-weight: 400; font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; line-height: 25px; text-rendering: optimizelegibility; font-size: 16px; padding-bottom: 5px; border-bottom: 1px solid rgb(238, 238, 238);"><span style="color: rgb(255, 0, 0);">公网</span>服务端配置</h3><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">首先修改 FRP 公网服务端 <span style="font-weight: 700;">frp<span style="color: rgb(255, 0, 0);">s</span>&#46;ini</span> 配置文件,通过 <span style="font-weight: 700;">vhost_http_port</span> 参数来设置 HTTP 访问端口,这里将 HTTP 访问端口设为 <span style="font-weight: 700;">8090</span></p><div class="code-toolbar" style="position: relative; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;"><pre class=" language-bash" style="padding: 1em; border-radius: 0&#46;3em; color: rgb(248, 248, 242); font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 12px; line-height: 1&#46;5; font-family: Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace; margin-top: 0&#46;5em; margin-bottom: 0&#46;5em; border-style: solid; border-color: rgb(230, 230, 230); background-color: rgb(39, 40, 34); overflow-wrap: normal; word-break: normal; text-shadow: rgba(0, 0, 0, 0&#46;3) 0px 1px; word-spacing: normal; tab-size: 4; hyphens: none; overflow: auto;"><code class=" language-bash" style="padding: 0px; border-radius: 3px; font-size: 10px; font-family: Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace; border: 0px; background: none; text-shadow: rgba(0, 0, 0, 0&#46;3) 0px 1px; word-spacing: normal; word-break: normal; overflow-wrap: normal; line-height: 1&#46;5; tab-size: 4; hyphens: none;">root@U-NAS:~/frp<span class="token comment" style="padding: 12px 0px 10px; position: relative; margin: 20px 0px; color: slategray;"># vi frps&#46;ini</span>
<span class="token punctuation">[</span>common<span class="token punctuation">]</span>
bind_port <span class="token operator">=</span> 7000
<span class="token comment" style="padding: 12px 0px 10px; position: relative; margin: 20px 0px; color: slategray;"># vhost_http_port 参数来设置 HTTP 访问端口,此处示例:8090</span>
vhost_http_port <span class="token operator">=</span> 8090
</code></pre><div class="toolbar" style="position: absolute; top: 0&#46;3em; right: 0&#46;2em; transition: opacity 0&#46;3s ease-in-out 0s; opacity: 0;"><div class="toolbar-item" style="display: inline-block;"><span style="color: rgb(187, 187, 187); font-size: 0&#46;8em; padding: 0px 0&#46;5em; background: rgba(224, 224, 224, 0&#46;2); box-shadow: rgba(0, 0, 0, 0&#46;2) 0px 2px 0px 0px; border-radius: 0&#46;5em;">Bash</span></div><div class="toolbar-item" style="display: inline-block;"><a style="color: rgb(187, 187, 187); cursor: pointer; font-size: 0&#46;8em; padding: 0px 0&#46;5em; background: rgba(224, 224, 224, 0&#46;2); box-shadow: rgba(0, 0, 0, 0&#46;2) 0px 2px 0px 0px; border-radius: 0&#46;5em;">Copy</a></div></div></div><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">在frp目录下输入【<span style="color: rgb(255, 0, 0);">&#46;/frps -c &#46;/frps&#46;ini</span>】命令启动 frps</p><div class="code-toolbar" style="position: relative; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;"><pre class=" language-bash" style="padding: 1em; border-radius: 0&#46;3em; color: rgb(248, 248, 242); font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 12px; line-height: 1&#46;5; font-family: Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace; margin-top: 0&#46;5em; margin-bottom: 0&#46;5em; border-style: solid; border-color: rgb(230, 230, 230); background-color: rgb(39, 40, 34); overflow-wrap: normal; word-break: normal; text-shadow: rgba(0, 0, 0, 0&#46;3) 0px 1px; word-spacing: normal; tab-size: 4; hyphens: none; overflow: auto;"><code class=" language-bash" style="padding: 0px; border-radius: 3px; font-size: 10px; font-family: Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace; border: 0px; background: none; text-shadow: rgba(0, 0, 0, 0&#46;3) 0px 1px; word-spacing: normal; word-break: normal; overflow-wrap: normal; line-height: 1&#46;5; tab-size: 4; hyphens: none;">root@U-NAS:~/frp<span class="token comment" style="padding: 12px 0px 10px; position: relative; margin: 20px 0px; color: slategray;"># &#46;/frps -c &#46;/frps&#46;ini</span>
2019/12/18 13:59:34 <span class="token punctuation">[</span>I<span class="token punctuation">]</span> <span class="token punctuation">[</span>service&#46;go:141<span class="token punctuation">]</span> frps tcp listen on 0&#46;0&#46;0&#46;0:7000
2019/12/18 13:59:34 <span class="token punctuation">[</span>I<span class="token punctuation">]</span> <span class="token punctuation">[</span>service&#46;go:183<span class="token punctuation">]</span> http <span class="token function" style="color: rgb(230, 219, 116);">service</span> listen on 0&#46;0&#46;0&#46;0:8090
2019/12/18 13:59:34 <span class="token punctuation">[</span>I<span class="token punctuation">]</span> <span class="token punctuation">[</span>root&#46;go:205<span class="token punctuation">]</span> start frps success</code></pre><div class="toolbar" style="position: absolute; top: 0&#46;3em; right: 0&#46;2em; transition: opacity 0&#46;3s ease-in-out 0s; opacity: 0;"><div class="toolbar-item" style="display: inline-block;"><span style="color: rgb(187, 187, 187); font-size: 0&#46;8em; padding: 0px 0&#46;5em; background: rgba(224, 224, 224, 0&#46;2); box-shadow: rgba(0, 0, 0, 0&#46;2) 0px 2px 0px 0px; border-radius: 0&#46;5em;">Bash</span></div><div class="toolbar-item" style="display: inline-block;"><a style="color: rgb(187, 187, 187); cursor: pointer; font-size: 0&#46;8em; padding: 0px 0&#46;5em; background: rgba(224, 224, 224, 0&#46;2); box-shadow: rgba(0, 0, 0, 0&#46;2) 0px 2px 0px 0px; border-radius: 0&#46;5em;">Copy</a></div></div></div><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">出现【<span style="color: rgb(255, 0, 0);">Start frps success</span>】代表运行成功</p><h3 style="margin: 5px 0px 20px; color: rgb(85, 85, 85); font-weight: 400; font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; line-height: 25px; text-rendering: optimizelegibility; font-size: 16px; padding-bottom: 5px; border-bottom: 1px solid rgb(238, 238, 238);"><span style="color: rgb(0, 0, 255);">内网</span>客户端配置</h3><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">其次我们在修改 FRP 内网客户端 <span style="font-weight: 700;">frp<span style="color: rgb(0, 0, 255);">c</span>&#46;ini</span> 配置文件并增加如下内容:</p><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">这里通过 <span style="font-weight: 700;">local_port</span> 和 <span style="font-weight: 700;">custom_domains</span> 参数来设置本地机器上 Web 服务对应的<span style="font-weight: 700;">端口</span>和<span style="font-weight: 700;">自定义的域名</span>,这里我们分别设置端口为 <span style="font-weight: 700;">80</span>,对应自定义域名 例如:<span style="font-weight: 700;">www&#46;666&#46;com</span></p><div class="code-toolbar" style="position: relative; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;"><pre class=" language-ini" style="padding: 1em; border-radius: 0&#46;3em; color: rgb(248, 248, 242); font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 12px; line-height: 1&#46;5; font-family: Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace; margin-top: 0&#46;5em; margin-bottom: 0&#46;5em; border-style: solid; border-color: rgb(230, 230, 230); background-color: rgb(39, 40, 34); overflow-wrap: normal; word-break: normal; text-shadow: rgba(0, 0, 0, 0&#46;3) 0px 1px; word-spacing: normal; tab-size: 4; hyphens: none; overflow: auto;"><code class=" language-ini" style="padding: 0px; border-radius: 3px; font-size: 10px; font-family: Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace; border: 0px; background: none; text-shadow: rgba(0, 0, 0, 0&#46;3) 0px 1px; word-spacing: normal; word-break: normal; overflow-wrap: normal; line-height: 1&#46;5; tab-size: 4; hyphens: none;"># frpc&#46;ini 内容
[common]
server_addr = 192&#46;168&#46;44&#46;130
# 对应公网服务端的IP
server_port = 7000
# 对应公网服务端的端口
[ssh]
type = tcp
local_ip = 127&#46;0&#46;0&#46;1
local_port = 22
remote_port = 6000
[web]
type = http
# local_port 为本地机器上 Web 服务对应的端口
local_port = 80
# custom_domains 为本地机器上 Web 服务对应的自定义的域名
custom_domains = www&#46;666&#46;com</code></pre><div class="toolbar" style="position: absolute; top: 0&#46;3em; right: 0&#46;2em; transition: opacity 0&#46;3s ease-in-out 0s; opacity: 0;"><div class="toolbar-item" style="display: inline-block;"><span style="color: rgb(187, 187, 187); font-size: 0&#46;8em; padding: 0px 0&#46;5em; background: rgba(224, 224, 224, 0&#46;2); box-shadow: rgba(0, 0, 0, 0&#46;2) 0px 2px 0px 0px; border-radius: 0&#46;5em;">Ini</span></div><div class="toolbar-item" style="display: inline-block;"><a style="color: rgb(187, 187, 187); cursor: pointer; font-size: 0&#46;8em; padding: 0px 0&#46;5em; background: rgba(224, 224, 224, 0&#46;2); box-shadow: rgba(0, 0, 0, 0&#46;2) 0px 2px 0px 0px; border-radius: 0&#46;5em;">Copy</a></div></div></div><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">在frp目录下输入【<span style="color: rgb(0, 0, 255);">&#46;/frpc -c &#46;/frpc&#46;ini</span>】命令启动 <span style="font-weight: 700;">frp<span style="color: rgb(0, 0, 255);">c</span></span></p><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;"> </p><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">最后将自定义域名 例如:www&#46;666&#46;com</p><ul style="margin: 0px 0px 16px 26px; padding: 0px; list-style: none; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;"><li style="line-height: 20px; margin-bottom: 10px; padding-left: 20px;">A记录 解析到【<span style="font-weight: 700;">frp<span style="color: rgb(0, 0, 255);">c</span>&#46;ini</span> 配置文件内 <span style="font-weight: 700;">server_addr</span> 对应的 IP】</li><li style="line-height: 20px; margin-bottom: 10px; padding-left: 20px;">CNAME 解析到【<span style="font-weight: 700;">frp<span style="color: rgb(0, 0, 255);">c</span>&#46;ini</span> 配置文件内 <span style="font-weight: 700;">server_addr</span> 对应的域名】</li></ul><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">现在便可以通过【 http://www&#46;666&#46;com:8090 】这个 URL 访问到处于内网机器上对应的 Web 服务。</p><ul style="margin: 0px 0px 16px 26px; padding: 0px; list-style: none; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;"><li style="line-height: 20px; margin-bottom: 10px; padding-left: 20px;"><span style="font-weight: 700;">8090</span>端口对应的是 <span style="color: rgb(255, 0, 0);">公网</span>服务端 <span style="font-weight: 700;">frp<span style="color: rgb(255, 0, 0);">s</span>&#46;ini</span> 配置文件中 <span style="font-weight: 700;">vhost_http_port</span> 对应的 <span style="font-weight: 700;">8090</span> 端口</li></ul><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;"> </p><blockquote style="margin: 15px auto; padding: 10px 15px 5px; border-width: 1px 1px 1px 3px; border-style: solid; border-color: rgb(214, 233, 198); border-image: initial; background-color: rgb(244, 255, 239); font-size: 12px; line-height: 20px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;"><p style="margin-bottom: 5px; font-size: 14px; line-height: 30px; padding: 0px;"><span style="font-weight: 700;">HTTPS 服务配置方法类似</span></p><p style="margin-bottom: 5px; font-size: 14px; line-height: 30px; padding: 0px;"><span style="color: rgb(255, 0, 0);">公网</span>服务端 <span style="font-weight: 700;">frp<span style="color: rgb(255, 0, 0);">s</span>&#46;ini</span> 配置文件 将 <span style="font-weight: 700;">vhost_http_port</span> 替换为 <span style="font-weight: 700;">vhost_https_port</span></p><p style="margin-bottom: 5px; font-size: 14px; line-height: 30px; padding: 0px;"><span style="color: rgb(0, 0, 255);">内网</span>客户端 <span style="font-weight: 700;">frp<span style="color: rgb(0, 0, 255);">c</span>&#46;ini</span> 配置文件 将 <span style="font-weight: 700;">type = http</span> 替换为 <span style="font-weight: 700;">type = https</span></p></blockquote><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;"> </p><h2 style="margin: 20px -20px 20px -24px; color: rgb(85, 85, 85); font-weight: 400; font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; line-height: 18px; text-rendering: optimizelegibility; font-size: 18px; padding: 10px 20px 9px; border-left: 4px solid rgb(66, 139, 202); background-color: rgb(251, 251, 251);">通过密码保护你的 Web 服务</h2><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">由于所有客户端共用一个 FRP <span style="color: rgb(255, 0, 0);">公网</span>服务端的 HTTP 服务端口,任何知道你的域名和 URL 的人都能访问到你部署在<span style="color: rgb(0, 0, 255);">内网</span>的 Web 服务,但是在某些场景下需要确保只有限定的用户才能访问。</p><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">FRP 支持通过 HTTP Basic Auth 来保护你的 Web 服务,使用户需要通过用户名和密码才能访问到你的网页服务。需要实现此功能主要需要在 FRP <span style="color: rgb(0, 0, 255);">内网</span>客户端 <span style="font-weight: 700;">frp<span style="color: rgb(0, 0, 255);">c</span>&#46;ini</span> 配置文件中添加用户名和密码的设置。</p><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">该功能目前仅限于 HTTP 类型的代理。</p><div class="code-toolbar" style="position: relative; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;"><pre class=" language-ini" style="padding: 1em; border-radius: 0&#46;3em; color: rgb(248, 248, 242); font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 12px; line-height: 1&#46;5; font-family: Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace; margin-top: 0&#46;5em; margin-bottom: 0&#46;5em; border-style: solid; border-color: rgb(230, 230, 230); background-color: rgb(39, 40, 34); overflow-wrap: normal; word-break: normal; text-shadow: rgba(0, 0, 0, 0&#46;3) 0px 1px; word-spacing: normal; tab-size: 4; hyphens: none; overflow: auto;"><code class=" language-ini" style="padding: 0px; border-radius: 3px; font-size: 10px; font-family: Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace; border: 0px; background: none; text-shadow: rgba(0, 0, 0, 0&#46;3) 0px 1px; word-spacing: normal; word-break: normal; overflow-wrap: normal; line-height: 1&#46;5; tab-size: 4; hyphens: none;"># frpc&#46;ini 内容
[common]
server_addr = 192&#46;168&#46;44&#46;130
# 对应公网服务端的IP
server_port = 7000
# 对应公网服务端的端口
[ssh]
type = tcp
local_ip = 127&#46;0&#46;0&#46;1
local_port = 22
remote_port = 6000
[web]
type = http
# local_port 为本地机器上 Web 服务对应的端口
local_port = 80
# custom_domains 为本地机器上 Web 服务对应的自定义的域名
custom_domains = www&#46;666&#46;com
# 设置认证的用户名
http_user = 666
# 设置认证的密码
http_pwd = 123456
</code></pre><div class="toolbar" style="position: absolute; top: 0&#46;3em; right: 0&#46;2em; transition: opacity 0&#46;3s ease-in-out 0s; opacity: 0;"><div class="toolbar-item" style="display: inline-block;"><span style="color: rgb(187, 187, 187); font-size: 0&#46;8em; padding: 0px 0&#46;5em; background: rgba(224, 224, 224, 0&#46;2); box-shadow: rgba(0, 0, 0, 0&#46;2) 0px 2px 0px 0px; border-radius: 0&#46;5em;">Ini</span></div><div class="toolbar-item" style="display: inline-block;"><a style="color: rgb(187, 187, 187); cursor: pointer; font-size: 0&#46;8em; padding: 0px 0&#46;5em; background: rgba(224, 224, 224, 0&#46;2); box-shadow: rgba(0, 0, 0, 0&#46;2) 0px 2px 0px 0px; border-radius: 0&#46;5em;">Copy</a></div></div></div><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">在frp目录下输入【<span style="color: rgb(0, 0, 255);">&#46;/frpc -c &#46;/frpc&#46;ini</span>】命令启动 <span style="font-weight: 700;">frp<span style="color: rgb(0, 0, 255);">c</span></span></p><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;"> </p><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">这时访问 http://www&#46;666&#46;com:8090 这个 URL 时就需要输入配置的用户名和密码才能访问。</p><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;"> </p><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;"><span style="font-weight: 700;">效果演示</span></p><center style="color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;"><img alt="FRP通过密码保护Web服务" src="https://www&#46;nasge&#46;com/d/file/2019/12/18/95c1e95efb7e1887cfdebe1902292c60&#46;gif" style="height: 427px; max-width: 860px; border-radius: 5px; vertical-align: middle; margin: auto; padding: 5px; cursor: zoom-in; width: 800px;" /></center><h2 style="margin: 20px -20px 20px -24px; color: rgb(85, 85, 85); font-weight: 400; font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; line-height: 18px; text-rendering: optimizelegibility; font-size: 18px; padding: 10px 20px 9px; border-left: 4px solid rgb(66, 139, 202); background-color: rgb(251, 251, 251);">给 Web 服务增加自定义子域名托管</h2><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">在多人同时使用一个 frps 时,通过自定义二级域名的方式来使用会更加方便。</p><h3 style="margin: 5px 0px 20px; color: rgb(85, 85, 85); font-weight: 400; font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; line-height: 25px; text-rendering: optimizelegibility; font-size: 16px; padding-bottom: 5px; border-bottom: 1px solid rgb(238, 238, 238);"><span style="color: rgb(255, 0, 0);">公网</span>服务端配置</h3><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">首先修改在 FRP <span style="color: rgb(255, 0, 0);">公网</span>服务端 <span style="font-weight: 700;">frp<span style="color: rgb(255, 0, 0);">s</span>&#46;ini</span> 配置文件,通过 <span style="font-weight: 700;">subdomain_host</span> 参数来设置自定义域名,这里将参数设置为 例如:<span style="font-weight: 700;">777&#46;com</span></p><div class="code-toolbar" style="position: relative; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;"><pre class=" language-bash" style="padding: 1em; border-radius: 0&#46;3em; color: rgb(248, 248, 242); font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 12px; line-height: 1&#46;5; font-family: Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace; margin-top: 0&#46;5em; margin-bottom: 0&#46;5em; border-style: solid; border-color: rgb(230, 230, 230); background-color: rgb(39, 40, 34); overflow-wrap: normal; word-break: normal; text-shadow: rgba(0, 0, 0, 0&#46;3) 0px 1px; word-spacing: normal; tab-size: 4; hyphens: none; overflow: auto;"><code class=" language-bash" style="padding: 0px; border-radius: 3px; font-size: 10px; font-family: Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace; border: 0px; background: none; text-shadow: rgba(0, 0, 0, 0&#46;3) 0px 1px; word-spacing: normal; word-break: normal; overflow-wrap: normal; line-height: 1&#46;5; tab-size: 4; hyphens: none;"><span class="token comment" style="padding: 12px 0px 10px; position: relative; margin: 20px 0px; color: slategray;"># frps&#46;ini 内容</span>
<span class="token punctuation">[</span>common<span class="token punctuation">]</span>
bind_port <span class="token operator">=</span> 7000
<span class="token comment" style="padding: 12px 0px 10px; position: relative; margin: 20px 0px; color: slategray;"># vhost_http_port 参数来设置 HTTP 访问端口,此处示例:8090</span>
vhost_http_port <span class="token operator">=</span> 8090
<span class="token comment" style="padding: 12px 0px 10px; position: relative; margin: 20px 0px; color: slategray;"># subdomain_host 参数来设置  Web 服务增加自定义二级域名</span>
<span class="token comment" style="padding: 12px 0px 10px; position: relative; margin: 20px 0px; color: slategray;"># 将泛域名 *&#46;777&#46;com 解析到 frps 所在公网服务器的 IP 地址</span>
subdomain_host <span class="token operator">=</span> 777&#46;com</code></pre><div class="toolbar" style="position: absolute; top: 0&#46;3em; right: 0&#46;2em; transition: opacity 0&#46;3s ease-in-out 0s; opacity: 0;"><div class="toolbar-item" style="display: inline-block;"><span style="color: rgb(187, 187, 187); font-size: 0&#46;8em; padding: 0px 0&#46;5em; background: rgba(224, 224, 224, 0&#46;2); box-shadow: rgba(0, 0, 0, 0&#46;2) 0px 2px 0px 0px; border-radius: 0&#46;5em;">Bash</span></div><div class="toolbar-item" style="display: inline-block;"><a style="color: rgb(187, 187, 187); cursor: pointer; font-size: 0&#46;8em; padding: 0px 0&#46;5em; background: rgba(224, 224, 224, 0&#46;2); box-shadow: rgba(0, 0, 0, 0&#46;2) 0px 2px 0px 0px; border-radius: 0&#46;5em;">Copy</a></div></div></div><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">通过在 <span style="font-weight: 700;">frp<span style="color: rgb(255, 0, 0);">s</span></span> 的配置文件中配置 <span style="font-weight: 700;">subdomain_host</span>,就可以启用该特性。<br />之后在 <span style="font-weight: 700;">frp<span style="color: rgb(0, 0, 255);">c</span></span> 的 http、https 类型的代理中可以不配置 <span style="font-weight: 700;">custom_domains</span>,而是配置一个 <span style="font-weight: 700;">subdomain</span> 参数。</p><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">只需要将 <span style="font-weight: 700;">*&#46;{subdomain_host}</span> 解析到 <span style="font-weight: 700;">frp<span style="color: rgb(255, 0, 0);">s</span></span> 所在<span style="color: rgb(255, 0, 0);">公网</span>服务器。<br />例如:</p><ul style="margin: 0px 0px 16px 26px; padding: 0px; list-style: none; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;"><li style="line-height: 20px; margin-bottom: 10px; padding-left: 20px;"><span style="font-weight: 700;">subdomain_host</span> = 777&#46;com、<span style="color: rgb(255, 0, 0);">公网</span>服务器IP为 <span style="font-weight: 700;">192&#46;168&#46;44&#46;130</span></li><li style="line-height: 20px; margin-bottom: 10px; padding-left: 20px;">*&#46;777&#46;com A记录 泛解析为 192&#46;168&#46;44&#46;130</li></ul><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">在frp目录下输入【<span style="color: rgb(255, 0, 0);">&#46;/frps -c &#46;/frps&#46;ini</span>】命令启动 frps</p><div class="code-toolbar" style="position: relative; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;"><pre class=" language-bash" style="padding: 1em; border-radius: 0&#46;3em; color: rgb(248, 248, 242); font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 12px; line-height: 1&#46;5; font-family: Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace; margin-top: 0&#46;5em; margin-bottom: 0&#46;5em; border-style: solid; border-color: rgb(230, 230, 230); background-color: rgb(39, 40, 34); overflow-wrap: normal; word-break: normal; text-shadow: rgba(0, 0, 0, 0&#46;3) 0px 1px; word-spacing: normal; tab-size: 4; hyphens: none; overflow: auto;"><code class=" language-bash" style="padding: 0px; border-radius: 3px; font-size: 10px; font-family: Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace; border: 0px; background: none; text-shadow: rgba(0, 0, 0, 0&#46;3) 0px 1px; word-spacing: normal; word-break: normal; overflow-wrap: normal; line-height: 1&#46;5; tab-size: 4; hyphens: none;">root@U-NAS:~/frp<span class="token comment" style="padding: 12px 0px 10px; position: relative; margin: 20px 0px; color: slategray;"># &#46;/frps -c &#46;/frps&#46;ini</span>
2019/12/18 17:42:17 <span class="token punctuation">[</span>I<span class="token punctuation">]</span> <span class="token punctuation">[</span>service&#46;go:141<span class="token punctuation">]</span> frps tcp listen on 0&#46;0&#46;0&#46;0:7000
2019/12/18 17:42:17 <span class="token punctuation">[</span>I<span class="token punctuation">]</span> <span class="token punctuation">[</span>service&#46;go:183<span class="token punctuation">]</span> http <span class="token function" style="color: rgb(230, 219, 116);">service</span> listen on 0&#46;0&#46;0&#46;0:8090
2019/12/18 17:42:17 <span class="token punctuation">[</span>I<span class="token punctuation">]</span> <span class="token punctuation">[</span>service&#46;go:240<span class="token punctuation">]</span> Dashboard listen on 0&#46;0&#46;0&#46;0:7500
2019/12/18 17:42:17 <span class="token punctuation">[</span>I<span class="token punctuation">]</span> <span class="token punctuation">[</span>root&#46;go:205<span class="token punctuation">]</span> start frps success</code></pre><div class="toolbar" style="position: absolute; top: 0&#46;3em; right: 0&#46;2em; transition: opacity 0&#46;3s ease-in-out 0s; opacity: 0;"><div class="toolbar-item" style="display: inline-block;"><span style="color: rgb(187, 187, 187); font-size: 0&#46;8em; padding: 0px 0&#46;5em; background: rgba(224, 224, 224, 0&#46;2); box-shadow: rgba(0, 0, 0, 0&#46;2) 0px 2px 0px 0px; border-radius: 0&#46;5em;">Bash</span></div><div class="toolbar-item" style="display: inline-block;"><a style="color: rgb(187, 187, 187); cursor: pointer; font-size: 0&#46;8em; padding: 0px 0&#46;5em; background: rgba(224, 224, 224, 0&#46;2); box-shadow: rgba(0, 0, 0, 0&#46;2) 0px 2px 0px 0px; border-radius: 0&#46;5em;">Copy</a></div></div></div><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">出现【<span style="color: rgb(255, 0, 0);">Start frps success</span>】代表运行成功</p><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;"> </p><h3 style="margin: 5px 0px 20px; color: rgb(85, 85, 85); font-weight: 400; font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; line-height: 25px; text-rendering: optimizelegibility; font-size: 16px; padding-bottom: 5px; border-bottom: 1px solid rgb(238, 238, 238);"><span style="color: rgb(0, 0, 255);">内网</span>客户端配置</h3><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">其次我们在修改 FRP 内网客户端 <span style="font-weight: 700;">frp<span style="color: rgb(0, 0, 255);">c</span>&#46;ini</span> 配置文件并增加如下内容:</p><div class="code-toolbar" style="position: relative; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;"><pre class=" language-ini" style="padding: 1em; border-radius: 0&#46;3em; color: rgb(248, 248, 242); font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 12px; line-height: 1&#46;5; font-family: Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace; margin-top: 0&#46;5em; margin-bottom: 0&#46;5em; border-style: solid; border-color: rgb(230, 230, 230); background-color: rgb(39, 40, 34); overflow-wrap: normal; word-break: normal; text-shadow: rgba(0, 0, 0, 0&#46;3) 0px 1px; word-spacing: normal; tab-size: 4; hyphens: none; overflow: auto;"><code class=" language-ini" style="padding: 0px; border-radius: 3px; font-size: 10px; font-family: Consolas, Monaco, &quot;Andale Mono&quot;, &quot;Ubuntu Mono&quot;, monospace; border: 0px; background: none; text-shadow: rgba(0, 0, 0, 0&#46;3) 0px 1px; word-spacing: normal; word-break: normal; overflow-wrap: normal; line-height: 1&#46;5; tab-size: 4; hyphens: none;">[web_test]
type = http
local_port = 80
# subdomain 为 frps&#46;ini 配置文件内 subdomain_host = 777&#46;com 对应自定义子域名前缀
subdomain = test</code></pre><div class="toolbar" style="position: absolute; top: 0&#46;3em; right: 0&#46;2em; transition: opacity 0&#46;3s ease-in-out 0s; opacity: 0;"><div class="toolbar-item" style="display: inline-block;"><span style="color: rgb(187, 187, 187); font-size: 0&#46;8em; padding: 0px 0&#46;5em; background: rgba(224, 224, 224, 0&#46;2); box-shadow: rgba(0, 0, 0, 0&#46;2) 0px 2px 0px 0px; border-radius: 0&#46;5em;">Ini</span></div><div class="toolbar-item" style="display: inline-block;"><a style="color: rgb(187, 187, 187); cursor: pointer; font-size: 0&#46;8em; padding: 0px 0&#46;5em; background: rgba(224, 224, 224, 0&#46;2); box-shadow: rgba(0, 0, 0, 0&#46;2) 0px 2px 0px 0px; border-radius: 0&#46;5em;">Copy</a></div></div></div><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">在frp目录下输入【<span style="color: rgb(0, 0, 255);">&#46;/frpc -c &#46;/frpc&#46;ini</span>】命令启动 <span style="font-weight: 700;">frp<span style="color: rgb(0, 0, 255);">c</span></span></p><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;"> </p><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">FRP 服务端 和 FRP 客户端都启动成功后,通过 test&#46;777&#46;com 就可以访问到内网的 Web 服务。</p><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">同一个 HTTP 或 HTTPS 类型的代理中 <span style="font-weight: 700;">custom_domains</span> 和 <span style="font-weight: 700;">subdomain</span> 可以同时配置。</p><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">需要注意的是如果 FPR 服务端配置了 <span style="font-weight: 700;">subdomain_host</span>,则 <span style="font-weight: 700;">custom_domains</span> 中不能是属于 <span style="font-weight: 700;">subdomain_host</span> 的子域名或者泛域名(<span style="font-weight: 700;">subdomain_host</span>,<span style="font-weight: 700;">custom_domains</span> <span style="color: rgb(178, 34, 34);"><span style="font-weight: 700;">两个参数内域名不能相同</span></span>)。</p><div class="pages" style="text-align: center; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;"></div><p style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;"></p><p align="center" style="margin-bottom: 15px; color: rgb(85, 85, 85); font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;">---------------------------------- THE END ----------------------------------</p></div>
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|腾飞在线 ( 冀ICP备05002530号 )

GMT+8, 2026-2-13 08:20 , Processed in 0.058168 second(s), 18 queries .

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表