sword

frp源码编译及404页面修改教程
前言frp 是一个高性能的反向代理应用,可以轻松地进行内网穿透,对外网提供服务,支持 TCP、UDP、HTTP、H...
扫描右侧二维码阅读全文
17
2018/11

frp源码编译及404页面修改教程

前言

frp 是一个高性能的反向代理应用,可以轻松地进行内网穿透,对外网提供服务,支持 TCP、UDP、HTTP、HTTPS 等协议类型,并且 web 服务支持根据域名进行路由转发。

Github: https://github.com/fatedier/frp

当然frp作者已经提供多达20种已编译好的各种版本可以供大家使用,几乎不需要自己编译。

但是有时候我们需要自定义一些内容,这时候就需要自行编译了。

搭建GO环境

1、安装依赖

#Ubuntu
sudo apt-get install bison ed gawk gcc libc6-dev make
#CentOS
sudo yum install gcc

2、下载go支持包
各版本的下载地址 https://www.golangtc.com/static/go/,我使用的是当前最新的1.9.2版本

wget https://www.golangtc.com/static/go/1.9.2/go1.9.2.linux-amd64.tar.gz

3、解压go包

sudo tar -C /usr/local -xzf go1.9.2.linux-amd64.tar.gz

4、添加环境变量和go工作区

vim /etc/profile

在文件的底部添加以下两行:

export PATH=$PATH:/usr/local/go/bin  
export GOPATH=/usr/local/gopath

:wq 保存退出后,重新加载环境变量

source /etc/profile

至此,go环境搭建完毕。

下载编译frp

直接运行以下命令

go get github.com/fatedier/frp 
cd /usr/local/gopath/src/github.com/fatedier/frp/
make

make 编译完成后,frp里会多出一个bin目录,放着frpc和frps,对应客户端和服务端的可执行文件。服务端上只需要用到 frps,可以删掉 frpc,客户端则相反。

修改404页面

404页面在源码路径utils/vhost/resource.go文件里,
更改部分如图

请输入图片描述

404源码示例1

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>404 找不到此页面/(ㄒoㄒ)/~~</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">

<style>*{padding:0;margin:0}a{text-decoration:none}.notfoud-container .img-404{height:155px;background:url(https://www.ituku.me/images/0c87.png) center center no-repeat;-webkit-background-size:150px auto;margin-top:40px;margin-bottom:20px}.notfoud-container .notfound-p{line-height:22px;font-size:17px;padding-bottom:15px;border-bottom:1px solid #f6f6f6;text-align:center;color:#262b31}.notfoud-container .notfound-reason{color:#9ca4ac;font-size:13px;line-height:13px;text-align:left;width:210px;margin:0 auto}.notfoud-container .notfound-reason p{margin-top:13px}.notfoud-container .notfound-reason ul li{margin-top:10px;margin-left:36px}.notfoud-container .notfound-btn-container{margin:40px auto 0;text-align:center}.notfoud-container .notfound-btn-container .notfound-btn{display:inline-block;border:1px solid #ebedef;background-color:#239bf0;color:#fff;font-size:15px;border-radius:5px;text-align:center;padding:10px;line-height:16px;white-space:nowrap}</style>
</head>
<body>

    <div class="notfoud-container">
        <div class="img-404">
        </div>
        <p class="notfound-p">哎呀迷路了...</p>
        <div class="notfound-reason">
            <p>可能的原因:</p>
            <ul>
                <li>frpc没有启动成功</li>
                <li>域名不正确</li>
                <li>内网端不存在该页面</li>
                <li>我们的服务器被外星人劫持了</li>
            </ul>
        </div>
        
        <div class="notfound-reason">
            <p align="center"><a href=http://freenat.win/>免费frp内网穿透服务</a>
        </div>

    </div>

</body>

404源码示例2

<head>
<meta charset="UTF-8" http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>404-找不到此页面/(ㄒoㄒ)/~~</title>
<style type="text/css">
 
.head404{ width:196px; height:196px; margin:50px auto 0 auto; background:url(https://www.ituku.me/images/0zHK.png) no-repeat; }
 
.txtbg404{ width:499px; height:169px; margin:10px auto 0 auto; background:url(https://www.ituku.me/images/0DQE.png) no-repeat;}
 
.txtbg404 .txtbox{ width:390px; position:relative; top:30px; left:60px;color:#eee; font-size:13px;}
 
.txtbg404 .txtbox p {margin:5px 0; line-height:18px;}
 
.txtbg404 .txtbox .paddingbox { padding-top:15px;}
 
.txtbg404 .txtbox p a { color:#eee; text-decoration:none;}
 
.txtbg404 .txtbox p a:hover { color:#FC9D1D; text-decoration:underline;}
 
</style>
</head>


<body bgcolor="#494949">
 
       <div class="head404"></div>
 
       <div class="txtbg404">
 
  <div class="txtbox">
 
      <p>对不起,您请求的页面不存在、或已被删除、或暂时不可用</p>
 
      <p class="paddingbox">可能的原因:</p>
      <p>1、frpc没有启动成功;</p>
      <p>2、域名不正确;</p>
      <p>3、内网端不存在该网页;</p>
      <p>4、frp服务器被外星人劫持了。</p>
      <p>&nbsp;</p>
        
      <p align="center"><a href=http://freenat.win/>免费frp内网穿透服务</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Powered by <a href="http://agint.me/">SWORD'S BLOG</a></p>
 
    </div>
 
  </div>

</body>

你可以自行更改后再编译,就可以了

参考文章:https://bingozb.github.io/55.html

Last modification:February 2nd, 2019 at 08:21 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment

7 comments

  1. 21世纪经典畅销版 LINUX经典丛书 R11; RelaxSite   ( Other System Other System / Other Browser Other Browser )

    [...]本文链接:https://sword.studio/104.html[...]

  2. 21世纪经典畅销版 LINUX经典丛书 R11; RelaxSite   ( Other System Other System / Other Browser Other Browser )

    [...]本文链接:https://sword.studio/104.html[...]

  3.   ( Windows 10 x64 Edition Windows 10 x64 Edition / 搜狗高速浏览器 搜狗高速浏览器 )

    谢谢博主的回复

  4.   ( Windows 10 x64 Edition Windows 10 x64 Edition / 搜狗高速浏览器 搜狗高速浏览器 )

    可是命令行中的没有make指令,build好像也不行

    1. sword   ( Windows 10 x64 Edition Windows 10 x64 Edition / Google Chrome 80.0.3987.106 Google Chrome 80.0.3987.106 )
      @刘

      新版本的frp可以直接配置404,不需要编译啦,去用新版本就行了

  5.   ( Windows 10 x64 Edition Windows 10 x64 Edition / 搜狗高速浏览器 搜狗高速浏览器 )

    博主你好,请问这个操作在window上怎么操作,我的服务器是windows的

    1. sword   ( Android 8.1.0 Android 8.1.0 / WebView 4.0 WebView 4.0 )
      @刘

      win可以搜索cmd进入命令行模式