frp内网穿透服务器搭建及免费frp服务器提供

通过自定义域名访问部署于内网的 web 服务【frp内网穿透服务器搭建及免费frp服务器提供】有时想要让其他人通过域名访问或者测试我们在本地搭建的 web 服务,但是由于本地机器没有公网 IP,无法将域名解析到本地的机器,通过 frp 就可以实现这一功能,以下示例为 http 服务,https 服务配置方法相同,vhost_http_port 替换为 vhost_https_port,type 设置为 https 即可 。

  1. 修改 frps.ini 文件,设置 http 访问端口为 8080:
# frps.ini[common]bind_port = 7000vhost_http_port = 8080
  1. 启动 frps:
./frps -c ./frps.ini
  1. 修改 frpc.ini 文件,假设 frps 所在的服务器的 IP 为 x.x.x.x,local_port 为本地机器上 web 服务对应的端口, 绑定自定义域名 www.yourdomain.com:
# frpc.ini[common]server_addr = x.x.x.xserver_port = 7000[web]type = httplocal_port = 80custom_domains = www.yourdomain.com
  1. 启动 frpc:
./frpc -c ./frpc.ini
  1. 将 www.yourdomain.com 的域名 A 记录解析到 IP x.x.x.x,如果服务器已经有对应的域名,也可以将 CNAME 记录解析到服务器原先的域名 。
  2. 通过浏览器访问 http://www.yourdomain.com:8080 即可访问到处于内网机器上的 web 服务 。
https://github.com/fatedier/frp/blob/master/README_zh.md
1使用nohup来启动这是frps的后台启动(路径写你服务器上的绝对路径),如果要查看日志的话,就直接使用cat nohup.out,就可以查看了 。
nohup /path/to/your/fprs -c-c /path/to/your/frps.ini
这是frpc的后台启动
nohup /path/to/your/fprc -c-c /path/to/your/frpc.ini
2使用systemctl来控制启动这个方法比较好用,很方便
sudo vim /lib/systemd/system/frps.service
在frps.service里写入以下内容
[Unit]Description=fraps serviceAfter=network.target syslog.targetWants=network.target[Service]Type=simple#启动服务的命令(此处写你的frps的实际安装目录)ExecStart=/your/path/frps -c /your/path/frps.ini[Install]WantedBy=multi-user.target
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
然后就启动frps
sudo systemctl start frps
再打开自启动
sudo systemctl enable frps
  • 如果要重启应用,可以这样,sudo systemctl restart frps
  • 如果要停止应用,可以输入,sudo systemctl stop frps
  • 如果要查看应用的日志,可以输入,sudo systemctl status frps
3使用supervisor来控制首先先安装supervisor,我用的ubuntu
sudo apt install supervisor
创建 supervisor frps 配置文件,在 /etc/supervisor/conf.d 创建 frp.conf
[program:frp]command = /your/path/frps -c /your/path/frps.iniautostart = true
  • 1
  • 2
  • 3
同样是你的绝对路径 。
写完以后,要重新加载一下supervisor
# 重启supervisorsudo systemctl restart supervisor# 查看supervisor运行状态sudo supervisorctl status
  • 1
  • 2
  • 3
  • 4

    相关经验推荐