手把手教你搭建内网穿透服务器
创始人
2025-01-18 06:04:10
0

有时候我们需要把外网可以访问自己的内网,比如在微信公众号开发调用接口时为了方便调试就需要配置回调地址或者是想把自己的nas可以在不在家就能访问,这时候就需要内网穿透。使用内网穿透主要有几种方式,1.使用内网穿透服务商提供的服务,但是这种需要付费,免费的话有很多限制而且还可能绑定不成功。2.自己搭建,自己搭建的话如果是单纯的想让外网访问只需要自己有一台外网服务器,如果是为了微信公众号开发调试则还需要一个域名。 

  1. 下载frp:

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

2.解压:

tar -zxvf  frp_0.45.0_linux_amd64.tar.gz 

4.进入frp_0.45.0_linux_amd64

cd  frp_0.45.0_linux_amd64

5.修改配置文件

vi frps.ini

内容如下:

[common]
#服务器的IP
server_addr = xxx.xx.xxx.xxx
#服务器配置的端口
server_port = 3030
#服务器配置的Token(密码)
token = xxxxx
#这个案例是http网页的
[web]
#映射类型,详见frpc_full.ini
type = http
#需要映射的本地服务ip
local_ip = 192.168.1.7
#需要映射的本地服务端口
local_port = 6080
#映射绑定的域名,没有域名可以直接写你的服务器IP
custom_domains =nat.xxx.com

6.启动

nohup ./frps -c frps.ini & > /dev/null 2> /dev/null &

查看ps -ef | grep frp

图片

7.在客户端(本地)配置Frpc

1.从Github下载Frpc,下载后解压到文件夹里

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

图片

8.配置Frpc.ini

如下:

[common]
#服务器的IP
server_addr = xxx.xxx.xxx.xxx
#服务器配置的端口
server_port = 3030
#服务器配置的Token
token = xxx

[web]
#映射类型,详见frpc_full.ini
type = http
#需要映射的本地服务ip
local_ip = 192.168.1.7
#需要映射的本地服务端口
local_port = 6080
#映射绑定的域名或服务器IP
custom_domains =nat.xxx.com

9.运行

图片

10 配置服务端nginx

#user nobody;
worker_processes 1;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;

#log_format main ‘$remote_addr – $remote_user [$time_local] “$request” ‘
# ‘$status $body_bytes_sent “$http_referer” ‘
# ‘”$http_user_agent” “$http_x_forwarded_for”‘;

#access_log logs/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;

upstream nat-server {
server xxx.xx.xxx.xxx:3031;
}

server {
listen 80;
server_name xxxx.com;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
root /usr/share/nginx/html;
index index.html index.htm;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}

server {
listen 80;
server_name www.xxxx.com;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
root /usr/share/nginx/html;
index index.html index.htm;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}

server {
listen 80;
server_name nat.xxxx.com;

proxy_set_header Host $host:80;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection “upgrade”;

proxy_connect_timeout 7d;
proxy_send_timeout 7d;
proxy_read_timeout 7d;

location / {
proxy_pass http://nat-server;
proxy_read_timeout 36000;
}
}
}

重新加载nginx配置

/usr/local/nginx/sbin/nginx -s reload

域名绑定

nat.xxxx.com

访问 xxxx.xxxx.xxxx:35000

图片

相关内容

热门资讯

围绕透视问题!wepoker透... 围绕透视问题!wepoker透视脚本视频,德普之星怎么开辅助,其实是真的有挂(有挂透视)1、德普之星...
揭露一下!光明辅助器,潮汕掌上... 揭露一下!光明辅助器,潮汕掌上娱破解,总是真的有挂(哔哩哔哩)1、打开软件启动之后找到中间准星的标志...
无独有偶!wepoker私人局... 无独有偶!wepoker私人局透视,智星德州可以透视吗,都是确实有挂(有挂透明挂)1.智星德州可以透...
教你一下!四川家园游戏辅助软件... 教你一下!四川家园游戏辅助软件,阿拉斗牌作弊视频,一贯是真的有挂(哔哩哔哩)四川家园游戏辅助软件能透...
黑科技辅助挂!wepoker怎... 黑科技辅助挂!wepoker怎么看底牌,德扑之星辅助工具如何设置,一贯存在有挂(有挂秘籍)1、很好的...
解迷一下!福州十八扑外卦视频,... 解迷一下!福州十八扑外卦视频,wepoker辅助器免费下载,原来真的是有挂(哔哩哔哩);1、操作简单...
据玩家消息!hhpoker到底... 据玩家消息!hhpoker到底可以作弊吗,德普之星辅助工具如何设置,竟然真的有挂(有挂分享)据玩家消...
关于一下!微信开心泉州辅助器,... 关于一下!微信开心泉州辅助器,赣牌圈的好牌几率,一直存在有挂(哔哩哔哩)1、超多福利:超高返利,海量...
今日!德州局怎么透视,智星菠萝... 今日!德州局怎么透视,智星菠萝可以辅助吗,切实是真的有挂(确实有挂)1、智星菠萝可以辅助吗免费脚本咨...
教你一下!边锋干瞪眼ios辅助... 教你一下!边锋干瞪眼ios辅助,祺友互娱脚本,竟然有挂(哔哩哔哩);1、每一步都需要思考,不同水平的...