ZEEKLING

Stay simple, stay naive.

目录
frp 内网穿透
/  

frp 内网穿透

目的

本人使用了树莓派作为了家里一直吃灰的服务器,想让树莓派上面的东西外网可以访问(博客也是部署在树莓派上面的),所以就有了 frp 内网穿透这一说法。

frps

首先需要一台远程服务器,我选择的是阿里云的服务器,最开始选择的国外的 vultr,后来试了下 hostwind,要么是网速比较慢,要么是丢包比较严重,所以放弃了,选择了阿里云香港区的服务器,也是可以翻墙,虽然总体算下来应该比国外的贵一点。但是网速快。而且我选择的是最便宜的,所以就可以忽略了。哈哈哈

  1. 下载 frp 软件,地址https://github.com/fatedier/frp/releases 并且解压到 /usr/local/frps 下面
  2. 修改配置,我的配置主要如下:
 1[common]
 2bind_port = 7000
 3vhost_http_port = 8080
 4vhost_https_port = 4443
 5bind_udp_port = 7001
 6admin_port = 7400
 7admin_user = admin
 8admin_pwd = admin
 9max_pool_count = 5
10dashboard_port = 7500
11dashboard_pwd = admin
12max_pool_count = 100
13token = 123456
  1. /usr/local/frps 下面执行 ./frps -c ./frps.ini & 就可以了
  2. 增加定时任务:*/1 * * * * cd /usr/local/frps && ./frps -c frps.ini &

frpc

  1. 修改配置
 1[common]
 2server_addr = aliyun ip
 3server_port = 7000
 4token = 123456
 5pool_count = 100
 6login_fail_exit = false
 7use_compression = true
 8use_encryption = true
 9
10[ssh]
11type = tcp
12local_ip = 127.0.0.1
13local_port = 22
14remote_port = 6000
15custom_domains = ssh.zeekling.cn
16use_compression = true
17use_encryption = true
18
19[root]
20type = http
21local_port = 80
22custom_domains = zeekling.cn
23use_compression = true
24use_encryption = true
25
26[www]
27type = http
28local_port = 80
29custom_domains = www.zeekling.cn
30use_compression = true
31use_encryption = true
32
33[blog]
34type = http
35local_port = 8080
36custom_domains = blog.zeekling.cn
37use_compression = true
38use_encryption = true
39
40[pan]
41type = http
42local_port = 81
43custom_domains = www.zeek-pan.cn
44use_compression = true
45use_encryption = true
  1. 连接 frps
1./frpc -c ./frpc.ini > /tmp/frpc.log 2>&1 &
  1. 监控脚本
1frp=`ps -ef | grep frpc | wc -l`
2if [ "${frp}" -eq "1" ];then
3        cd frp_0.26.0_linux_arm && ./frpc -c ./frpc.ini > /tmp/frpc.log 2>&1 &
4fi

frps 和 nginx 都是用 80 端口

nginx 加入如下配置即可

 1server {
 2        listen 80 default_server;
 3        listen [::]:80 default_server;
 4
 5        root /var/www/html;
 6
 7        index index.html index.htm index.nginx-debian.html;
 8
 9        server_name _;
10
11        location / {
12                proxy_pass http://127.0.0.1:8080; # 本地服务器地址
13                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
14                proxy_set_header Host $http_host;
15                proxy_set_header Upgrade $http_upgrade;
16                proxy_set_header Connection "upgrade";
17        }
18
19        location ~ .(jpg|png|gif|css|js)$ { # 缓存
20                proxy_pass http://127.0.0.1:8080; # 本地服务器地址
21                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
22                proxy_set_header Host $http_host;
23                proxy_set_header Upgrade $http_upgrade;
24                proxy_set_header Connection "upgrade";
25                proxy_cache cache_one;
26                proxy_cache_valid 200 302 1h;
27                proxy_cache_valid 301 1d;
28                proxy_cache_valid any 1m;
29                expires 30d;
30                proxy_redirect off;
31                add_header wall "hey!guys!give me a star.";
32        }
33}

标 题:frp 内网穿透
作 者:ZEEKLING
描 述:Stay simple, stay naive.