1.下载frp:

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

2.解压压缩包:

tar -zxvf frp_0.37.0_linux_amd64.tar.gz
3.将解压好的文件移动

mv frp_0.37.0_linux_amd64 /usr/local/frp

4.进入刚才移动的文件所在的文件夹

cd /usr/local/frp/
5.修改Frps的配置文件

vim 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.启动Frps

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

查看ps -ef | grep frp

关闭Frps:

kill -9 【PID】
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

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

*避免选错,建议把所有frps的文件和exe都删除

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