通过自定义域名访问部署于内网的 web 服务【frp内网穿透服务器搭建及免费frp服务器提供】有时想要让其他人通过域名访问或者测试我们在本地搭建的 web 服务,但是由于本地机器没有公网 IP,无法将域名解析到本地的机器,通过 frp 就可以实现这一功能,以下示例为 http 服务,https 服务配置方法相同,vhost_http_port 替换为 vhost_https_port,type 设置为 https 即可 。
- 修改 frps.ini 文件,设置 http 访问端口为 8080:
- 启动 frps:
./frps -c ./frps.ini
- 修改 frpc.ini 文件,假设 frps 所在的服务器的 IP 为 x.x.x.x,local_port 为本地机器上 web 服务对应的端口, 绑定自定义域名
www.yourdomain.com
:
- 启动 frpc:
./frpc -c ./frpc.ini
- 将
www.yourdomain.com
的域名 A 记录解析到 IPx.x.x.x
,如果服务器已经有对应的域名,也可以将 CNAME 记录解析到服务器原先的域名 。
- 通过浏览器访问
http://www.yourdomain.com:8080
即可访问到处于内网机器上的 web 服务 。
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
sudo systemctl start frps
再打开自启动
sudo systemctl enable frps
- 如果要重启应用,可以这样,
sudo systemctl restart frps
- 如果要停止应用,可以输入,
sudo systemctl stop frps
- 如果要查看应用的日志,可以输入,
sudo systemctl status frps
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
相关经验推荐
- 带古风的情侣网名大全
- |电脑怎么设置固定的内网IP?这篇文章告诉你
- vivo|内外网的区别
- |怎么查看外网IP地址和内网IP地址
- 存储器|苹果被工信部点名后,国内网友又提出灵魂三问?库克:省点电吧
- nas|满速、瞬连丨最好用的内网穿透工具,亲身体验 NKN 方案
- |什么是电脑内网?什么是电脑外网?内网与外网有什么区别与联系?
- iPad|Linux新手入门系列:搭建局域网/内网的yum仓库
- 大学生群体数据分析:2021年中国55.9%大学生通过国内网购平台购买电子产品