Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
377 views
in Technique[技术] by (71.8m points)

wordpress - How do I get a Docker container that's requesting urls from itself to go via reverse proxy?

I am trying to fix "Failed to connect to myexample.com port 443: Connection refused". I think this is what's going on. Help would be amazing!

I have a Wordpress Docker container that is sending requests to itself. So curl -v https://myexample.com will return the above error. These are failing I think because the container doesn't support https. HTTPS is the job of the reverse proxy (traefik) that's in another container.

With my docker-compose file in mind, what's the solution for this?

One option I can imagine is for the WP container to have myexample.com resolve to the proxy instead of itself. The proxy can then manage the https request and send the response back to the WP container.

Is that the correct / best way of doing it?

If so, on the WP container, how do I resolve myexample.com to the proxy? (obviously with the hosts file but how/what values). This is my summarised docker-compose file.


services:
  traefik:
    image: traefik:2.3
    container_name: traefik
    network_mode: web
    ports:
      - '80:80'
      - '443:443'
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - $PWD/traefik:/etc/traefik

  db:
    ...

  www:
    image: wordpress:latest
    container_name: www
    networks:
      - web
      - internal
    depends_on:
      - db
    links:
      - db:mysql
    volumes:
      - wp-data:/var/www/html
    labels:
      - traefik.http.routers.retro.rule=Host(`myexample.com`)
      - traefik.http.routers.retro.middlewares=myHeaders@file
      - traefik.http.routers.retro.tls=true
      - traefik.http.routers.retro.tls.certResolver=lets-encrypt
      - traefik.port=80

volumes:
  wp-data:

networks:
  web:
    external: true
  internal:
    external: false

Thank you!

question from:https://stackoverflow.com/questions/65876746/how-do-i-get-a-docker-container-thats-requesting-urls-from-itself-to-go-via-rev

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...