zl程序教程

您现在的位置是:首页 >  大数据

当前栏目

内网穿透利器frp部署配置指南

配置部署 指南 利器 穿透 frp
2023-06-13 09:13:17 时间

· · 220 次点击 ·
·
开始浏览    

这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。

frp是一个使用go语言开发的反向代理服务,可用于内网穿透,支持tcp, udp协议,为http和https协议提供了额外的能力,且尝试性支持了点对点穿透。 由于ngrok 2.x已经闭源,ngrok 1.x已不再维护,所以这里尝试使用frp替代ngrok作为个人的内网穿透工具。

0.前提条件 一台Linux云主机(这里是CentOS 7),并要求具有固定公网IP暴露这台云主机指定端口的能力 有一个域名解析到这个公网IP,如frp.frognew.com和*.frp.frognew.com解析到这个公网IP 1. 下载frp服务端frps和客户端frpc可执行文件

分别在服务器和个人本地机器上,从[https://github.com/fatedier/frp/releases]下载对应平台的frp服务端frps和客户端frpc可执行文件。 这里下载的0.29版本。

服务端:


wget https://github.com/fatedier/frp/releases/download/v0.29.0/frp_0.29.0_linux_amd64.tar.gz

tar -zxvf frp_0.29.0_linux_amd64.tar.gz

cd frp_0.29.0_linux_amd64

mkdir /usr/local/frp

cp frps /usr/local/frp

cp frps.ini /usr/local/frp

2. 配置启动服务端frps

编写frps的Systemd配置文件/etc/systemd/system/frps.service:


[Unit]

Description=Frp Server Service

After=network.target

[Service]

Type=simple

User=nobody

Restart=on-failure

RestartSec=5s

ExecStart=/usr/local/frp/frps -c /usr/local/frp/frps.ini

[Install]

WantedBy=multi-user.target

修改frps的配置文件/usr/local/frp/frps.ini:


[common]

bind_port = 17000

vhost_http_port = 8082

token = 12345678

启动frps:


systemctl enable frps

systemctl start frps

netstat -nltp | grep frps

tcp6 0 0 :::17000 :::* LISTEN 32481/frps

tcp6 0 0 :::8082 :::* LISTEN 32481/frps

3.nginx配置

接下来配置nginx反向代理frps的http服务:


server {

 listen 80;

 server_name *.frp.frognew.com;

 rewrite ^(.*)$ https://$host$1 permanent;


proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host:8082; proxy_set_header X-Nginx-Proxy true; proxy_set_header Connection ""; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_certificate /etc/letsencrypt/live/frognew.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/frognew.com/privkey.pem; location / { # proxy_intercept_errors on; # error_page 404 /404.html; proxy_pass http://127.0.0.1:8082;
4.frp客户端配置

使用python在本地快速启动一个http服务用于测试:



python3 -m http.server 8080

下面将使用frp将这个http服务暴露到公网,编写frp客户端frpc的配置文件frpc.ini:


[common]

server_addr = frp.frognew.com

server_port = 17000

tls_enable = true

token = 12345678


使用http://demo.frp.frognew.com即可从公网访问前面使用python启动的用于测试的http服务。

上面只是frp的基本功能,frp还提供更多的功能。 关于frp的更多内容可以查看官方文档frp。

220 次点击  
加入收藏