注意服务端和客户端的版本是需要一致的
如只有一端不知道版本可以进入目录通过./frps -v或者./frpc -v查看版本号
对于没有使用过frp的,可以看我之前写 树莓派实现内网穿透的那篇博客
1、下载SSL证书
这里我使用阿里云的服务器,所以就在阿里云上申请一个免费的证书。具体操作过程就不多解释了。。。
注意下载要是nginx的证书
2、使用frp进行https代理
此方式需要注意的是这里的证书是放在客户端下的
- 代理服务器(服务器端)设置
进入frps.ini,输入命令
vim frps.ini
编辑
[common]
bind_addr = 0.0.0.0
bind_port = 7000 #服务器开放端口,用于客户端与服务器通信
vhost_http_port = 80 #http虚拟端口,http请求
vhost_https_port = 443 #hhtps虚拟端口
token = XXXXX #验证信息,客户端需一致
dashboard_user = admin # 管理页面用户名
dashboard_pwd = admin@123 # 管理员密码
dashboard_port = 81 # 管理后台的端口
然后运行
nohup ./frps -c ./frps.ini &> frps.log &
- 被代理服务器设置
首先上传证书
server_addr = 192.168.100.100 #服务端的IP地址,好像也可以写域名,没试过
server_port = 7000 #服务端端口
token = XXXXX #验证信息,客户端需一致
local_ip = 127.0.0.1
log_file = ./frpc.log
[test_http] #Http服务,映射的是服务端http80端口
type = http #服务方式
local_ip = 127.0.0.1 #服务端ip,可写本地,局域网等做反向代理的ip
local_port = 8000 #服务端端口
custom_domains = test.test.com #需要反向代理的域名,就是服务端要代理的域名
[https] #Https服务,映射的是服务端https443端口
type = https #服务方式
local_ip = 127.0.0.1 #服务端ip,可写本地,局域网等做反向代理的ip
local_port = 8000 #服务端端口
custom_domains = test.test.com #需要反向代理的域名,就是服务端要代理的域名
# 以下为https新加的内容
plugin = https2http #将 https请求转换成http请求后再发送给本地服务
plugin_local_addr = 127.0.0.1:8000 #转换http后的端口
#证书相关配置
plugin_crt_path = /usr/local/frp_0.37.1_linux_amd64/5414927_jonion.top.pem #注意后缀
plugin_key_path = /usr/local/frp_0.37.1_linux_amd64/5414927_jonion.top.key #注意后缀
plugin_host_header_rewrite = 127.0.0.1
plugin_header_X-From-Where = frp
保存,运行
nohup ./frpc -c ./frpc.ini &> frpc.log &
3、使用frp和Nginx进行https代理
这里说明一下原理:当你访问页面的时候,通过Nginx监听80端口(http)和443端口(https),所有http请求将重定向https请求。接着Nginx将请求转发给frp的http虚拟端口,然后最后将请求发给frp客户端。
- 设置Nginx
那么我们首先设置Nginx的配置文件,要是对Nginx不大懂的,可以看我写的另外一篇(虽然写的也很简单)。
上传证书
关闭Nginx服务器
systemctl stop nginx.service
编辑配置文件
server {
listen 443 ssl;
ssl_certificate /etc/nginx/5414927_jonion.top.pem; # 证书存放位置
ssl_certificate_key /etc/nginx/5414927_jonion.top.key; # 证书存放位置
server_name jonion.top; #自己的网站域名
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
proxy_pass http://127.0.0.1:6666; #frp设置的端口
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_max_temp_file_size 0;
proxy_redirect off;
proxy_read_timeout 240s;
}
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
server {
listen 80; #监听80端口
server_name jonion.top; #你自己的网站
return 301 https://$server_name$request_uri;
}
运行Nginx
systemctl restart nginx.service
- 设置代理服务器frps.ini
[common]
bind_addr = 0.0.0.0
bind_port = 7000
vhost_http_port = 6666 #http端口,被代理端与代理端进行http通讯
vhost_https_port = 6667
token = XXXXX
dashboard_user = admin # 管理页面用户名
dashboard_pwd = admin@123 # 管理员密码
dashboard_port = 81
运行
nohup ./frps -c ./frps.ini &> frps.log &
- 设置被代理服务器frpc.ini
[common]
server_addr = 59.110.152.137
server_port = 7000
token = XXXXX
local_ip = 127.0.0.1
log_file = ./frpc.log
[http]
type = http
local_ip = 127.0.0.1
local_port = 80
remote_port=6666
custom_domains = jonion.top #你自己的域名
运行
nohup ./frpc -c ./frpc.ini &> frpc.log &
然后就可以访问啦,欢迎访问我的博客野生程序员