找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
广告投放联系QQ68610888
查看: 31690|回复: 382

[N1盒子] frp内网穿透+nginx,实现无端口访问【完整教程】

 火... [复制链接]
发表于 2019-9-21 11:43 | 显示全部楼层 |阅读模式
本帖最后由 efnic 于 2019-9-21 12:26 编辑

介绍
frp 是一个可用于内网穿透的高性能的反向代理应用,支持 tcp, udp , http, https, kcp 协议,为 http 和 https 应用协议提供了额外的能力,且尝试性支持了点对点穿透。

地址
项目页:https://github.com/fatedier/frp
下载页:https://github.com/fatedier/frp/releases

必备条件
具备公网IP服务器
有自己的域名
代码高亮,详情查阅:https://www.iyuu.cn/archives/286/
系统环境
服务器:centos 7.2 64位
客户端:小钢炮 Linux beikeyun 4.4.167 #1 SMP Mon May 6 01:01:07 CST 2019 aarch64 GNU/Linux
请根据平台选择正确的frp服务端、客户端,服务端与客户端版本号必须一致。

服务端部署
下载服务端
选择适合自己平台的frp服务端,我的服务器平台是amd64,所以下载这个。

  1. # 下载frp v0.29.0
  2. wget https://github.com/fatedier/frp/releases/download/v0.29.0/frp_0.29.0_linux_amd64.tar.gz
  3. # 解压
  4. tar zxf ./frp_0.29.0_linux_amd64.tar.gz
  5. cd ./frp_0.29.0_linux_amd64
复制代码


编辑服务端配置:
代码高亮,详情查阅:https://www.iyuu.cn/archives/286/具体配置含义请查阅:README_zh.mdfrps 完整配置文件
frps.ini配置文件:
  1. [common]
  2. bind_port = 5005
  3. dashboard_port = 5004
  4. dashboard_user = admin
  5. dashboard_pwd = admin
  6. vhost_http_port = 5000
  7. vhost_https_port = 5001
  8. subdomain_host = frp.iyuu.cn
  9. token = 123456789
复制代码


frps.service配置文件:
  1. [Unit]
  2. Description=Frp Server Service
  3. After=network.target

  4. [Service]
  5. User=root
  6. Restart=on-failure
  7. RestartSec=5s
  8. ExecStart=/usr/local/bin/frps -c /etc/frps.ini

  9. [Install]
  10. WantedBy=multi-user.target
复制代码


安装服务
sudo cp ./frps /usr/local/bin/frps
sudo cp ./frps.ini /etc/frps.ini
sudo cp ./systemd/frps.service /usr/lib/systemd/system/frps.service
systemctl enable frps
systemctl start frps

开机启动frps:
systemctl enable frps
启动frps:
systemctl start frps
停止frps:
systemctl stop frps
重启frps:
systemctl restart frps
查看frps状态:
systemctl status frps

删除服务的命令:
systemctl stop frps
sudo rm /usr/local/bin/frps
sudo rm /etc/frps.ini
sudo rm /usr/lib/systemd/system/frps.service

配置nginx实现无端口访问
1、 frp.iyuu.cn做A记录,解析至IP;
2、 *.frp.iyuu.cn做CNAME记录,解析至frp.iyuu.cn;
3、 新建frp.conf配置文件(内容如下),复制到nginx的配置目录/conf/vhost内,不同服务器可能不一样,请确认;
配置nginx反向代理,将来自*.frp.iyuu.cn的80端口请求,分发至frp服务器http请求的监听端口。
  1. server {
  2.     listen 80;
  3.     server_name *.frp.iyuu.cn;
  4.     location / {
  5.         proxy_pass http://127.0.0.1:5000;
  6.         proxy_set_header    Host            $host:80;
  7.         proxy_set_header    X-Real-IP       $remote_addr;
  8.         proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
  9.         proxy_hide_header   X-Powered-By;
  10.     }
  11. }
  12. server {
  13.     listen 80;
  14.     server_name frp.iyuu.cn;
  15.     location / {
  16.         proxy_pass http://127.0.0.1:5004;
  17.         proxy_set_header    Host            $host:80;
  18.         proxy_set_header    X-Real-IP       $remote_addr;
  19.         proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
  20.         proxy_hide_header   X-Powered-By;
  21.     }
  22. }
复制代码

复制frp.conf命令:
sudo cp ./frp.conf /path/nginx-1.8.1/conf/vhost/
4、 重启nginx
5、 访问测试:http://frp.iyuu.cn
到此,服务端已经部署完毕。如果无法访问,请检查防火墙、安全组,放行相关端口。

客户端部署
选择frp客户端
下载适合自己平台的frpc客户端,下载、解压命令与服务端类似,也可以手动下载解压。
小钢炮是arm64平台,并且内置frpc客户端,只是版本没那么高,可以替换升级一下。
https://github.com/fatedier/frp/ ... _linux_arm64.tar.gz

编辑客户端配置

frpc.ini配置文件,小钢炮内路径/etc/frpc.ini
  1. # [common] is integral section
  2. [common]
  3. # A literal address or host name for IPv6 must be enclosed
  4. # in square brackets, as in "[::1]:80", "[ipv6-host]:http" or "[ipv6-host%zone]:80"
  5. server_addr=frp.iyuu.cn
  6. server_port=5005
  7. # if you want to connect frps by http proxy or socks5 proxy, you can set http_proxy here or in global environment variables
  8. # it only works when protocol is tcp
  9. # http_proxy = http://user:passwd@192.168.1.128:8080
  10. # http_proxy = socks5://user:passwd@192.168.1.128:1080
  11. # console or real logFile path like ./frpc.log
  12. log_file=/var/log/frpc.log
  13. # trace, debug, info, warn, error
  14. log_level=info
  15. log_max_days=3
  16. # for authentication
  17. token=123456789
  18. # set admin address for control frpc's action by http api such as reload
  19. admin_addr=0.0.0.0
  20. admin_port=7400
  21. admin_user=admin
  22. admin_passwd=admin
  23. # connections will be established in advance, default value is zero
  24. pool_count=5
  25. # if tcp stream multiplexing is used, default is true, it must be same with frps
  26. tcp_mux=true
  27. # your proxy name will be changed to {user}.{proxy}
  28. user=hk
  29. # decide if exit program when first login failed, otherwise continuous relogin to frps
  30. # default is true
  31. login_fail_exit=false
  32. # communication protocol used to connect to server
  33. # now it supports tcp and kcp, default is tcp
  34. protocol=tcp
  35. # specify a dns server, so frpc will use this instead of default one
  36. # dns_server = 8.8.8.8
  37. # proxy names you want to start divided by ','
  38. # default is empty, means all proxies
  39. # start = ssh,dns
  40. # heartbeat configure, it's not recommended to modify the default value
  41. # the default value of heartbeat_interval is 10 and heartbeat_timeout is 90
  42. heartbeat_interval=10
  43. heartbeat_timeout=90
  44. admin_pwd=570100
  45. # specify a dns server, so frpc will use this instead of default one
  46. dns_server=119.29.29.29

  47. [dashboard_hk]
  48. type=http
  49. local_ip=127.0.0.1
  50. local_port=80
  51. use_encryption=false
  52. use_compression=true
  53. remote_port=
  54. subdomain=hk
复制代码

配置含义请参考:frpc 完整配置文件,根据需要添加代理设置,然后重启frpc。
访问测试:http://*.frp.iyuu.cn*替换为您实际的 subdomain参数)。

如何升级frp到最新版本?
服务端frps升级
下载最新版frp文件
停止frps服务:systemctl stop frps
用新版本覆盖旧版本
如果使用systemd的,记得覆盖:cp frps /usr/local/bin/
启动新版本frps:systemctl start frps
客户端frpc升级,与服务端类似。代码高亮,详情查阅:https://www.iyuu.cn/archives/286/



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×

评分

参与人数 1恩山币 +2 收起 理由
zhl416 + 2 别跟小白解释,无知不可怕,关键自己无知还要怼别人那绝对无药可救 哈哈

查看全部评分

我的恩山、我的无线 The best wifi forum is right here.
发表于 2019-9-21 11:46 | 显示全部楼层
谢谢分享!!!!!
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2019-9-21 12:14 | 显示全部楼层
本帖最后由 linksys_wifi 于 2019-9-21 12:16 编辑

唉!有公网IP和自己的域名,还用得着内网穿透吗?

点评

说的对,公网ip用不了80端口,域名一样要加端口  详情 回复 发表于 2019-10-23 17:50
比如家里没公网ip,需要内网穿透呢? 要么自己搭,要么用网上免费的或者收费的。这里教的是自己搭建frps服务器的技术。  详情 回复 发表于 2019-9-21 12:28
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 发表于 2019-9-21 12:28 | 显示全部楼层
linksys_wifi 发表于 2019-9-21 12:14
唉!有公网IP和自己的域名,还用得着内网穿透吗?

比如家里没公网ip,需要内网穿透呢?
要么自己搭,要么用网上免费的或者收费的。这里教的是自己搭建frps服务器的技术。
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2019-9-21 12:29 | 显示全部楼层
感谢楼主分享
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2019-9-21 12:37 | 显示全部楼层
学习学习,感谢分享教程。
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2019-9-21 12:38 | 显示全部楼层
感谢楼主分享!!!!
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2019-9-21 12:56 | 显示全部楼层
牛逼啊🐂🍺
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2019-9-21 13:31 | 显示全部楼层
感谢楼主分享
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2019-9-21 14:05 | 显示全部楼层

感谢楼主分享
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2019-9-21 14:12 | 显示全部楼层
的风格的公司都或多或少都会
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2019-9-21 15:50 | 显示全部楼层
好帖子必须顶
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2019-9-21 16:48 | 显示全部楼层
frp 是一个可用于内网穿透的高性能的反向代理应用
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2019-9-21 16:56 | 显示全部楼层
拿一台电脑来做FRP服务器,然后又拿一个N1小钢炮来做web服务器?脑子烧坏了?

点评

像我,有自己的博客www.iyuu.cn,腾讯云的3年600元不到; 家里是电信宽带,有公网ip。www.dawei.hk,映射了81、88、9091、9092等端口,玩过的都知道干啥用的。  详情 回复 发表于 2019-9-22 13:19
很多人都有自己的公网服务器有独立IP,比如600元3年的阿里元,腾讯云等,放个博客、跑个网站等等。 如果家里没有公网ip,想远程添加以下下载任务,管理机器之类的操作,怎么办?这个教程可以帮到你。 所谓,你所理  详情 回复 发表于 2019-9-22 13:17
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2019-9-21 16:59 | 显示全部楼层
感谢分享 学习一下
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

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

本版积分规则

有疑问请添加管理员QQ86788181|手机版|小黑屋|Archiver|恩山无线论坛(常州市恩山计算机开发有限公司版权所有) ( 苏ICP备05084872号 )

GMT+8, 2024-3-29 19:15

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

| 江苏省互联网有害信息举报中心 举报信箱:js12377 | @jischina.com.cn 举报电话:025-88802724 本站不良内容举报信箱:68610888@qq.com 举报电话:0519-86695797

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