本文使用apisix打造家庭NAS网关,并通过cloudflare进行穿透,可免公网IP访问。首先你的NAS支持Docker,没有NAS也没有关系,只要你的电脑支持Docker同样可以参照该教程。
打开docker -> 镜像 -> 仓库 -> 设置 -> 添加
仓库名称:Docker Hub
库地址: https://hub.docker.com/
请在nas中建立docker需要挂载的目录,目录如下:
文件目录: /我的文件/docker/apisix/apisix/conf/config.yaml
apisix:
node_listen: 9080 # APISIX listening port
enable_ipv6: true # 开启ipv6支持
enable_control: true
control:
port: 9092
deployment:
admin:
allow_admin:
- 0.0.0.0/0
- ::0/0
admin_key:
- name: "admin"
key: edd1c9f034335f136f87ad84b625c8f1
role: admin # admin: manage all configuration data
- name: "viewer"
key: 4054f7cf07e344346cd3f287985e76a2
role: viewer
etcd:
host:
- "http://NAS的ip地址:12379" # etcd的地址
prefix: "/apisix" # apisix configurations prefix
timeout: 30 # 30 seconds
文件目录: /我的文件/docker/apisix/dashboard/conf.yaml
conf:
listen:
port: 9000 # `manager api` listening port
allow_list: # If we don't set any IP list, then any IP access is allowed by default.
- 0.0.0.0/0
- ::0/0
etcd:
endpoints: # supports defining multiple etcd host addresses for an etcd cluster
- "http://NAS的ip地址:12379" # etcd的地址
mtls:
enable: false
key_file: "" # Path of your self-signed client side key
cert_file: "" # Path of your self-signed client side cert
ca_file: "" # Path of your self-signed ca cert, the CA is used to sign callers'
prefix: /apisix # apisix config's prefix in etcd, /apisix by default
log:
error_log:
level: warn # supports levels, lower to higher: debug, info, warn, error, panic, fatal
file_path:
logs/error.log # supports relative path, absolute path, standard output
# such as: logs/error.log, /tmp/logs/error.log, /dev/stdout, /dev/stderr
access_log:
file_path:
logs/access.log # supports relative path, absolute path, standard output
authentication:
secret:
secret # secret for jwt token generation.
# NOTE: Highly recommended to modify this value to protect `manager api`.
# if it's default value, when `manager api` start, it will generate a random string to replace it.
expire_time: 3600 # jwt token expire time, in second
users: # yamllint enable rule:comments-indentation
- username: admin # username and password for login `manager api`
password: 这里是你的登录密码 # 这里是dashboard登录的密码,请尽量设置复杂一点
- username: user
password: 这里是你的登录密码 # 这里是dashboard普通用户登录的密码,请尽量设置复杂一点
plugins: # plugin list (sorted in alphabetical order)
- api-breaker
- authz-keycloak
- basic-auth
- batch-requests
- consumer-restriction
- cors
# - dubbo-proxy
- echo
# - error-log-logger
# - example-plugin
- fault-injection
- grpc-transcode
- hmac-auth
- http-logger
- ip-restriction
- jwt-auth
- kafka-logger
- key-auth
- limit-conn
- limit-count
- limit-req
# - log-rotate
# - node-status
- openid-connect
- prometheus
- proxy-cache
- proxy-mirror
- proxy-rewrite
- redirect
- referer-restriction
- request-id
- request-validation
- response-rewrite
- serverless-post-function
- serverless-pre-function
# - skywalking
- sls-logger
- syslog
- tcp-logger
- udp-logger
- uri-blocker
- wolf-rbac
- zipkin
- server-info
- traffic-split
a. 挂载目录: 我的文件/docker/
b. 设置启动命令:
sleep inf
c. 容器创建成功后,连接ssh进去执行
# 给etcd挂载的目录读写权限
chmod -R 777 /data/etcd
# 然后退出
exit
a. 设置挂载目录
挂载目录: 我的文件/docker/etcd/
容器内目录: /bitnami/etcd
b. 设置端口
本地端口
如图:
c. 设置环境变量
ALLOW_NONE_AUTHENTICATION: "yes"
ETCD_ADVERTISE_CLIENT_URLS: "http://NAS的ip地址:12379"
c. 在浏览器访问: http://NAS的ip地址:12379/version
返回如下信息说明正常访问:
{"etcdserver":"3.5.6","etcdcluster":"3.5.0"}
a. 挂载目录
挂载文件: 我的文件/docker/apisix/apisix/conf/config.yaml
容器内目录: /usr/local/apisix/conf/config.yaml
挂载日志目录: 我的文件/docker/apisix/apisix/logs/
容器内目录: /usr/local/apisix/logs
b. 开放端口
d. 验证服务
浏览器中访问:http://NAS的IP地址:19180/apisix/admin/services/
返回如下信息说明服务正常:
{"error_msg":"failed to check token"}
a. 设置挂载目录
挂载配置文件: /我的文件/docker/apisix/dashboard/conf.yaml
容器内目录文件: /usr/local/apisix-dashboard/conf/conf.yaml
b. 设置端口
d. 验证服务
浏览器中访问:http://NAS的IP地址:19000/
显示如下说明服务正常:
然后使用配置中的账户和密码登录。
地址:https://dash.cloudflare.com/login
然后确定提交
ssh中执行
cloudflared tunnel login
复制红框中的地址到浏览器中访问,登录cloudflare账号进行域名授权,然后选择如下图中域名进行授权
然后关闭页面
a. ssh中执行
cloudflared tunnel create 隧道名,请使用字母或者拼音
b. 绑定域名,并执行:
cloudflared tunnel route dns 隧道名 你的域名
cloudflared tunnel run --url http://你nas的IP地址:19080 隧道名 &
d. 浏览中输入https://你的域名 ,显示如下说明网关穿透成功
地址: http://你nas地址:19000
账户和密码参考上面dashboard的配置文件
配置内容按图中填写,然后下一步,然后提交
喜欢的小伙伴欢迎收藏+关注,我会不定时的分享一些干货,你们的支持就是我最大的动力。