• windows 部署 traefik 反向代理


    windows 部署 traefik 反向代理

     1. 下载 traefik :  https://github.com/traefik/traefik/releases

     

    文件下载并解压后: 

     

    解压后traefik目录下包括traefik.exe文件,在该目录下建立两个文件分别为traefik.toml和traefik-dynamic.toml,文件内容如下:
    traefik.toml

    [log]
      level = "DEBUG"
      filePath = "log-file.log"
    
    [accessLog]
      filePath =  "log-access.log"
      bufferingSize =  100
    
    [providers]
      [providers.file]
        filename = "traefik-dynamic.toml"
    
    [api]
      dashboard = true
      debug = true
    
    [entryPoints]
      [entryPoints.web]
        address = ":80"
      [entryPoints.web-secure]
        address = ":443"
      [entryPoints.dashboard]
        address = ":8080"
    
    [certificatesResolvers.sample.acme]
      email = "myemail@example.com"
      storage = "acme.json"
    
      [certificatesResolvers.sample.acme.httpChallenge]
        # used during the challenge
        entryPoint = "web"

    traefik-dynamic.toml

    [http]
        # Redirect to https
        [http.middlewares]
          [http.middlewares.test-redirectscheme.redirectScheme]
            scheme = "https"
    
        [http.routers]
           [http.routers.router-1]
              rule = "Host(`www.zhizhicloud.com`)"
              service = "console"
              entryPoints = ["web-secure"]
           [http.routers.router-2]
              rule = "Host(`www.zhizhicloud.com`) && PathPrefix(`/huhehaote/yxhk/`)"
              service = "huhehaote"
              entryPoints = ["web"]
               [http.routers.router-3]
              rule = "Host(`cdeserver.railplus.com`)"
              service = "cdeserver"
              entryPoints = ["web"]
           [http.routers.router-1.tls]
              certResolver = "sample"
        [http.services]
              [http.services.console.loadbalancer]
                [[http.services.console.loadbalancer.servers]]
                  url = "http://127.0.0.1:11778"
              [http.services.huhehaote.loadbalancer]
                [[http.services.huhehaote.loadbalancer.servers]]
                  url = "http://127.0.0.1:8000/huhehaote/yxhk/"
              [http.services.cdeserver.loadbalancer]
                [[http.services.cdeserver.loadbalancer.servers]]
                  url = "http://localhost:8092"
    
        [http.routers.my-api]
          rule = "Host(`traefik.zhizhicloud.com`)"
          entrypoints = ["web", "web-secure"]
          service = "api@internal"
          middlewares = ["auth"]
    
        [http.middlewares.auth.basicAuth]
          users = [
            "test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/",
          ]

    traefik-dynamic.toml文件中的www.zhizhicloud.comtraefik.zhizhicloud.com域名需要指向本机地址。

    在hosts文件中配置: 

    127.0.0.1 www.zhizhicloud.com
    127.0.0.1 traefik.zhizhicloud.com
    127.0.0.1 cdeserver.railplus.com

     启动服务 反向代理服务

    windows powershell 进入 treafik 目录,在 treafik目录下执行 traefik.exe 

    通过访问 http://traefik.zhizhicloud.com/dashboard/#/ 可以访问到traefik的dashboard页面如下:

     登录的账号与密码都是 test

     

    www.zhizhicloud.com域名反向到127.0.0.1:11778地址及端口。
    www.zhizhicloud.com/huhehaote/yxhk/反向到http://127.0.0.1:8000/huhehaote/yxhk/地址。
    这样通过traefik实现了基本的域名及路由地址到指定地址端口的反向代理。
    总结:
    正向代理就是本机访问外部服务配置代理转向,反向代理就是外部(如互联网手机端)通过域名或IP访问本地服务所需代理解析。本文只用traefik 2配置域名反向代理访问本机服务,正向代理配置基本相同不赘述。

     

      

    参考: https://www.jianshu.com/p/007252b709c3

  • 相关阅读:
    洛谷 P1032 字串变换
    map && multimap
    【转载】Pycharm调试高效,还是pdb调试高效? (在服务端)
    弱国无外交 弱国一定无外交吗
    [转发]Linux性能测试工具之Lmbench特性、安装及使用
    fedora21 桌面用户自动登录lightdm.conf -20190520 方法
    获取显卡硬件信息lspci -vnn | grep VGA -A 12
    mate桌面用户 root 自动登录lightdm.conf -20190520 方法【fedora 21】mate
    在线文本差异对比
    【科目三】机考 教练不出话 态度要好
  • 原文地址:https://www.cnblogs.com/1285026182YUAN/p/16708136.html
Copyright © 2020-2023  润新知