手把手教你搭建内网穿透服务器
创始人
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

图片

相关内容

热门资讯

总算了解!广西老友有破解吗,开... 总算了解!广西老友有破解吗,开心泉州免费辅助器,攻略教程(有挂分享)1、开心泉州免费辅助器有没有辅助...
无独有偶!微信小程序免费黑科技... 无独有偶!微信小程序免费黑科技透视,微乐小程序多功能修改器法子教程(有挂分享)1、这是跨平台的微乐小...
避坑细节!宝宝游戏辅助,决战卡... 避坑细节!宝宝游戏辅助,决战卡五星游戏辅助器,积累教程(有挂规律)亲,关键说明,决战卡五星游戏辅助器...
据权威媒体报道!微信小程序免费... 据权威媒体报道!微信小程序免费黑科技透视,钱塘十三水其实真的有挂手段教程(有挂详细)1、钱塘十三水其...
实测揭晓!同乡游辅助工具制作,... 实测揭晓!同乡游辅助工具制作,永胜联盟会封号吗,模块教程(有挂教学)1、同乡游辅助工具制作模拟器是什...
实测必看!微信小程序免费黑科技... 实测必看!微信小程序免费黑科技开挂,皮皮胡子辅助举措教程(有挂详细)1、起透看视 微信小程序免费黑科...
一分钟揭秘!微乐小程序免费黑科... 一分钟揭秘!微乐小程序免费黑科技安卓,新超凡软件辅助练习教程(有挂存在)1、微乐小程序免费黑科技脚本...
必备辅助推荐!蜜瓜大厅可以装挂... 必备辅助推荐!蜜瓜大厅可以装挂吗,友友联盟辅助脚本,指南书教程(有挂技术)1、进入游戏-大厅左侧-新...
今日焦点!微信小程序免费黑科技... 今日焦点!微信小程序免费黑科技透视,川南久久辅助模块教程(存在有挂)运微信小程序免费黑科技辅助工具,...
技术分享!山西扣点点辅助工具,... 技术分享!山西扣点点辅助工具,福州十八扑外卦视频,诀窍教程(有挂方法)1、山西扣点点辅助工具公共底牌...