【问题标题】:Access django by WAN IP instead of domain通过WAN IP而不是域访问django
【发布时间】:2021-09-25 11:20:19
【问题描述】:

我正在使用 pydanny-cookiecutter,在初始提示期间,我提供了一个我不再希望使用的域。

如何更新才能通过我正在运行的数字海洋水滴的 WAN IP 访问服务?

到目前为止,我已经在 droplet 中打开了端口 5000 和 5555,并手动(通过 ssh 进入 postgres 容器)将一条新记录插入到 django_sites 中,ID 为 2,域名和名称都作为 WAN IP。我还更新了设置 base.py 中的 SITE_ID=2。

我已经将 traefik.yml 上传到了下面,但是当我转到 WANIP:5000 或 WANIP:5555 时仍然无法访问页面

log:
  level: INFO

entryPoints:
  web:
    # http
    address: ":80"
    http:
      # https://docs.traefik.io/routing/entrypoints/#entrypoint
      redirections:
        entryPoint:
          to: web-secure

  web-secure:
    # https
    address: ":443"

  flower:
    address: ":5555"

certificatesResolvers:
  letsencrypt:
    # https://docs.traefik.io/master/https/acme/#lets-encrypt
    acme:
      email: "<REDACTED>@gmail.com"
      storage: /etc/traefik/acme/acme.json
      # https://docs.traefik.io/master/https/acme/#httpchallenge
      httpChallenge:
        entryPoint: web

http:
  routers:
    web-secure-router:
      rule: "HostRegexp(`<REDACTED WAN IP>`)"
      entryPoints:
        - web-secure
      middlewares:
        - csrf
      service: django
      tls:
        # https://docs.traefik.io/master/routing/routers/#certresolver
        certResolver: letsencrypt

    flower-secure-router:
      rule: "HostRegexp(`<REDACTED WAN IP>`)"
      entryPoints:
        - flower
      service: flower
      tls:
        # https://docs.traefik.io/master/routing/routers/#certresolver
        certResolver: letsencrypt

  middlewares:
    csrf:
      # https://docs.traefik.io/master/middlewares/headers/#hostsproxyheaders
      # https://docs.djangoproject.com/en/dev/ref/csrf/#ajax
      headers:
        hostsProxyHeaders: ["X-CSRFToken"]

  services:
    django:
      loadBalancer:
        servers:
          - url: http://django:5000

    flower:
      loadBalancer:
        servers:
          - url: http://flower:5555

providers:
  # https://docs.traefik.io/master/providers/file/
  file:
    filename: /etc/traefik/traefik.yml
    watch: true

谢谢!

【问题讨论】:

    标签: django traefik cookiecutter-django


    【解决方案1】:

    请注意,如果您使用 IP,SSL 证书 生成将不起作用,因此会在浏览器中引发警告:

    这是一个危险的网站。

    您要做的是在droplet中打开端口80和443,并通过http://[IP]访问应用程序。

    链接中没有端口,因为您正在配置 Traefik 以将 http(端口 80)和 https(端口 443)请求路由到 Django。

    这不是花的解决方案,但是我没有太多的花经验可说。

    【讨论】:

      猜你喜欢
      • 2015-01-01
      • 1970-01-01
      • 2020-05-14
      • 2018-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-20
      • 1970-01-01
      相关资源
      最近更新 更多