本文最后更新于 361 天前
开发环境:FnOS、腾讯云服务器
下载 Frp
Release v0.60.0 · fatedier/frp
客户端设置
编写配置文件
serverAddr = "106.54.224.68" #remote ip dress
serverPort = 7000 #communication port
[[proxies]]
name = "ssh-tcp"
type = "tcp"
localIP = "127.0.0.1"
localPort = 22
remotePort = 6000 #ssh port
[[proxies]]
name = "web"
type = "http" #同一域名只能有一个http转发
localPort = 8000
localIP = "127.0.0.1"
customDomains = ["nas.handong-joy.xyz"]
[[proxies]]
name = "xunlei"
type = "tcp" #其它页面tcp转发
localIP = "127.0.0.1"
localPort = 2345
remotePort = 2345
[[proxies]]
name = "bitdownload"
type = "tcp"
localIP = "127.0.0.1"
localPort = 8085
remotePort = 8085
[[proxies]]
name = "code-server"
type = "tcp"
localIP = "127.0.0.1"
localPort = 8443
remotePort = 8443
启动服务
./frpc -c ./frpc.toml
设置守护进程,开机自启
vim /etc/systemd/system/frpc.service
自启动任务
[Unit]
Description=frp_service
After=trim_connect.service #在某进程之后启动
After=docker.service
Wants=network-online.target #设置依赖(非强制)
[Service]
Type=simple
ExecStart=//data/frp/frp_0.60.0_linux_amd64/frpc -c //data/frp/frp_0.60.0_linux_amd64/frpc.toml
Restart=on-failure
[Install]
WantedBy=multi-user.target
自启动失败的解决方案
#E:/etc/systemd/system/rc-local.service:12: Support for option SysVStartPriority= has been removed and it is ignored
#旧版 systemd 支持的选项,用于设置服务的启动优先级。但在较新的 systemd 版本中,该选项已被移除或弃用
#解决方法:
sudo vim /etc/systemd/system/rc-local.service
#将第12行
SysVStartPriority=99
#注释
#SysVStartPriority=99
#重载守护进程
sudo systemctl daemon-reload
#验证是否生效
sudo systemd-analyze verify /etc/systemd/system/frpc.service
服务端设置
Frps
vim frps.toml
bindPort = 7000 # 与frpc通信端口
vhostHTTPPort = 8080 #http转发端口
Nginx
经过以上操作,使用云服务器端口 xx.xx.xx:8080 访问,若能访问网页,则已经转发成功。
由于 Frps 转发只是由 Nas 端口转发到了 云服务器 端口上,想要使用域名访问,仍需使用 Nginx 反向代理。
http
{
include mime.types;
#include luawaf.conf;
include proxy.conf;
lua_package_path "/www/server/nginx/lib/lua/?.lua;;";
default_type application/octet-stream;
server_names_hash_bucket_size 512;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 50m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/json image/jpeg image/gif image/png font/ttf font/otf image/svg+xml application/xml+rss text/x-js;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
limit_conn_zone $binary_remote_addr zone=perip:10m;
limit_conn_zone $server_name zone=perserver:10m;
server_tokens off;
access_log off;
server { listen 80; server_name nas.handong-joy.xyz; location / {# proxy_pass http://127.0.0.1:8080;# 代理到127.0.0.1:8080可以通过frp.3to.top:8080,但是frp.3to.top还是访问不到,所以改为下面配置 proxy_pass http://nas.handong-joy.xyz:8080; } } server { listen 2345; server_name nas.handong-joy.xyz; location / {# proxy_pass http://127.0.0.1:8080;# 代理到127.0.0.1:8080可以通过frp.3to.top:8080,但是frp.3to.top还是访问不到,所以改为下面配置 proxy_pass http://nas.handong-joy.xyz:2345; } }
server {
listen 8085;
server_name nas.handong-joy.xyz;
location / {
# proxy_pass http://127.0.0.1:8080;
# 代理到127.0.0.1:8080可以通过frp.3to.top:8080,但是frp.3to.top还是访问不到,所以改为下面配置
proxy_pass http://nas.handong-joy.xyz:8085;
}
}
server {
listen 8443;
server_name nas.handong-joy.xyz;
location / {
# proxy_pass http://127.0.0.1:8080;
# 代理到127.0.0.1:8080可以通过frp.3to.top:8080,但是frp.3to.top还是访问不到,所以改为下面配置
proxy_pass http://nas.handong-joy.xyz:8443;
}
}
至此,已经可以使用域名访问。
不错不错,学习了