手把手教你搭建内网穿透服务器
创始人
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、首先打开广东雀神智能插件安卓包最...
透视安装!德普辅助软件,德扑圈... 透视安装!德普辅助软件,德扑圈有透视吗,2024版教程(有挂解密)是一款可以让一直输的玩家,快速成为...
广东雀神智能插件安装可测试,长... 广东雀神智能插件安装可测试,长春科乐作弊,传送屋辅助软件下载最新版本更新内容黑科技1、不需要AI权限...
透视能赢!wepoker免费脚... 透视能赢!wepoker免费脚本咨询(透视)果然有挂(2025新版技巧);1、wepoker免费脚本...
透视了解!aapoker脚本,... 透视了解!aapoker脚本,aapoker辅助器怎么用,2025新版(有挂规律)1、aapoker...
透视软件!wepoker到底有... 透视软件!wepoker到底有没有透视(透视)都是是真的有挂(总结教程)进入游戏-大厅左侧-新手福利...
透视安装!德普之星私人局辅助器... 透视安装!德普之星私人局辅助器,德普之星私人局辅助免费,安装教程(有挂解密)(1)透视安装!德普之星...
透视总结!aapoker怎么提... 透视总结!aapoker怎么提高中牌率,aapoker插件,解密教程(有挂规律)透视总结!aapok...
透视辅助!aapoker辅助工... 透视辅助!aapoker辅助工具安全吗,aapoker ai插件,透明挂教程(有挂辅助)1、点击下载...
透视脚本!wepoker怎么看... 透视脚本!wepoker怎么看牌型(透视)好像是有挂(曝光教程)wepoker怎么看牌型是一种具有地...