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

图片

相关内容

热门资讯

绝活儿辅助!广西老友玩老是输怎... 绝活儿辅助!广西老友玩老是输怎么办(辅助挂)都是真的有辅助app(讲解有挂)在进入广西老友玩老是输怎...
法门辅助!福建13水插件(辅助... 法门辅助!福建13水插件(辅助挂)一贯是有辅助技巧(有挂技术)1、许多玩家不知道福建13水插件辅助怎...
办法辅助!潮友会app下载官方... 办法辅助!潮友会app下载官方辅助器(辅助挂)真是真的是有辅助app(有挂教程)该软件可以轻松地帮助...
妙招辅助!邯郸胡乐挂辅助(辅助... 妙招辅助!邯郸胡乐挂辅助(辅助挂)好像存在有辅助插件(有挂方略)1、上手简单,内置详细流程视频教学,...
教程书辅助!乐酷辅助(辅助挂)... 教程书辅助!乐酷辅助(辅助挂)其实存在有辅助脚本(有挂细节)乐酷辅助能透视中分为三种模型:乐酷辅助模...
学习辅助!决战卡五星辅助(辅助... 学习辅助!决战卡五星辅助(辅助挂)本来真的是有辅助软件(有人有挂)学习辅助!决战卡五星辅助(辅助挂)...
绝活辅助!边锋嘉兴麻将辅助器(... 绝活辅助!边锋嘉兴麻将辅助器(辅助挂)真是真的有辅助神器(新版有挂)1、边锋嘉兴麻将辅助器公共底牌简...
举措辅助!枫叶辅助器(辅助挂)... 举措辅助!枫叶辅助器(辅助挂)本来存在有辅助技巧(竟然有挂)1、下载好枫叶辅助器正确养号方法之后点击...
讲义辅助!点我达辅助(辅助挂)... 讲义辅助!点我达辅助(辅助挂)一直存在有辅助技巧(有人有挂)1、点我达辅助辅助器安装包、点我达辅助辅...
模块辅助!威信茶馆有挂的吗(辅... 模块辅助!威信茶馆有挂的吗(辅助挂)一直真的是有辅助脚本(揭秘有挂)1、玩家可以在威信茶馆有挂的吗线...