0

我很想为我的 Docker、Caddy、Hugo 和 Hugo-MX-Gateway 设置提供一些帮助。

我所拥有的一切都设置在我的 Docker-Compose 文件中。它处理我基于 Hugo 构建的静态站点的托管。这一切都有效。我正在尝试处理特定路径并将所有请求重定向到该路径到我的 hugo-mx-gateway 容器的根以处理发布请求。不幸的是,路径反向代理不起作用。

caddy_reverse_proxy:
        build: ./caddy_reverse_proxy/build
        ports:
            - 80:80  # HTTP
            - 443:443  # HTTPS
        environment:
            - CADDY_INGRESS_NETWORKS=caddy
        networks:
            - caddy
        volumes:
            - /var/run/docker.sock:/var/run/docker.sock
            - ./site/example/public:/public
            - caddy_data:/data
        restart: unless-stopped
        labels:
          # Create a TLS Snippet to import for every subdomain
          caddy: (tls)
          caddy.tls.dns: cloudflare ${CF_DNS_TOKEN}
          # Caddy Static Site Hosting
          caddy_0: example.com
          caddy_0.1_root: '* /public'
          caddy_0.2_file_server:
          caddy_0.3_import: tls
hugo-mx-gateway:
      image: rchakode/hugo-mx-gateway:1590272682
      container_name: hugo_mx_gateway
      networks:
        - caddy
      ports:
        - 9090:8080
      environment: 
        - SMTP_SERVER_ADDR=${SMTP_ADDR}
        - SMTP_VERITY_CERT=true
        - SMTP_CLIENT_USERNAME=${SMTP_USER}
        - SMTP_CLIENT_PASSWORD=${SMTP_PASS}
        - CONTACT_REPLY_EMAIL=noreply@${DOMAIN}
        - CONTACT_REPLY_BCC_EMAIL=mail@{DOMAIN}
        - ALLOWED_ORIGINS='*' # My attempt at debugging this
        # - ALLOWED_ORIGINS=caddy_reverse_proxy,127.0.0.1, ${DOMAIN}
      labels:
        caddy: ${DOMAIN}
        caddy.handle_path: '/mx-gateway/*'
        caddy.handle_path.reverse_proxy: '{{upstreams 9090}}'

总而言之,我得到一个像这样的球童文件:

example.com {
        root * /public
        file_server
        import tls
        handle_path /mx-gateway/* {
                reverse_proxy 172.25.0.8:9090
        }
}

Hugo-mx-gateway 有一个漂亮的小状态页面,当我通过本地网络访问它时它可以工作:http://192.168.1.2:9090/healthz,但是当我尝试通过我的反向代理访问它时(https: //example.com/mx-gateway/healthz)我没有得到回应,看着我看到的球童日志:

{"level":"error","ts":1623596455.0182462,"logger":"http.log.error","msg":"dial tcp 172.25.0.8:9090: connect: connection refused","request":{"remote_addr":"192.168.1.1:53414","proto":"HTTP/2.0","method":"GET","host":"example.com","uri":"/mx-gateway/healthz","headers":{"Sec-Fetch-User":["?1"],"Sec-Gpc":["1"],"Accept-Language":["en-CA,en-US;q=0.7,en;q=0.3"],"Accept-Encoding":["gzip, deflate, br"],"Cookie":["grav-tabs-state={%22tab-content.options.advanced%22:%22data.content%22%2C%22tab-content.meta.overrides.media%22:%22data.content%22%2C%22tab-content.languages.http_headers.markdown.caching.twig.assets.errors.debugger.media.session.advanced%22:%22data.content%22%2C%22tab-content.options%22:%22data.options%22%2C%22tab-content.options.advanced.blog%22:%22data.blog%22%2C%22tab-content.options.advanced.buttons%22:%22data.advanced%22%2C%22tab-content.options.advanced.features%22:%22data.features%22}; amp_ff9bd0=u4n9R9jj1HAeEGNP03BBms...1edcmj1k1.1edcmjq8f.0.0.0; PHPSESSID=h5u6otga9o5msfcgemkqb6g5u7s8781r"],"Sec-Fetch-Mode":["navigate"],"Sec-Fetch-Site":["none"],"Cache-Control":["max-age=0"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"],"Upgrade-Insecure-Requests":["1"],"Sec-Fetch-Dest":["document"],"Te":["trailers"],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:90.0) Gecko/20100101 Firefox/90.0"],"Dnt":["1"]},"tls":{"resumed":true,"version":772,"cipher_suite":4865,"proto":"h2","proto_mutual":true,"server_name":"example.com"}},"duration":0.000370186,"status":502,"err_id":"mrtb5bfba","err_trace":"reverseproxy.statusError (reverseproxy.go:843)"}

连接被拒绝方面让我认为 hugo-mx-gateway 正在拒绝它,所以我已将其更改为 allow_origins='*' 但它似乎仍然不起作用。我正在尝试轻松处理来自简单联系表单的 POST 请求。

4

0 回答 0