【问题标题】:Error: cURL error 28: Resolving timed out after 10000 milliseconds (http_request_failed) with nginx reverse proxy in docker错误:cURL 错误 28:使用 docker 中的 nginx 反向代理解决 10000 毫秒后超时(http_request_failed)
【发布时间】:2020-08-12 21:27:16
【问题描述】:

我正在尝试使用带有 Nginx 反向代理的 Docker Compose 设置本地 Wordpress 环境。 WordPress。工作,但在站点健康我得到:

Error: cURL error 28: Resolving timed out after 10000 milliseconds (http_request_failed)

这是我的 docker-compose 文件

version: '3.1'

services:

  web:
    image: nginx
    ports:
      - "80:80"
    volumes:
      - ./site.conf:/etc/nginx/conf.d/site.conf
    depends_on:
      - wordpress
      - db

  wordpress:
    image: wordpress
    expose:
      - 80
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: local_user
      WORDPRESS_DB_PASSWORD: secret
      WORDPRESS_DB_NAME: local
    volumes:
      - ./wordpress:/var/www/html

  db:
    image: mysql:5.7
    environment:
      MYSQL_DATABASE: local
      MYSQL_USER: local_user
      MYSQL_PASSWORD: secret
      MYSQL_ROOT_PASSWORD: root_secret
    ports:
      - 3306:3306
    volumes:
      - ./mysql:/var/lib/mysql

这是我的 Nginx 配置文件:

upstream backend{
    server wordpress:80;
}

server {
    listen 80;
    listen [::]:80;

    index index.php index.html;
    server_name bedrock.local; 
    # error_log  /var/log/nginx/error.log;
    # access_log /var/log/nginx/access.log;
    # root /code/web;

    location / {
        proxy_pass http://backend/;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }

}

bedrock.local 域在 /etc/hosts 中使用 127.0.0.1 本地解析 我没有使用 HTTPS(只是 HTTP)来简化测试。

谢谢!

【问题讨论】:

    标签: wordpress docker nginx nginx-reverse-proxy


    【解决方案1】:

    我遇到了同样的问题,由于 Docker 网络,Wordpress 容器无法访问公共 IP 地址上的网站。

    对此的最佳解决方案是在 docker-compose.yml 文件中将 fqdn 别名添加到 Nginx 容器中,以允许 Wordpress 在内部访问 Nginx。

    此配置将解决问题:

    web:
      image: nginx
      ports:
        - "80:80"
      volumes:
        - ./site.conf:/etc/nginx/conf.d/site.conf
      depends_on:
        - wordpress
        - db
      networks:
        default:
          aliases:
            - yourwebsite.com
            - www.yourwebsite.com
    

    【讨论】:

      猜你喜欢
      • 2017-10-20
      • 2017-07-27
      • 1970-01-01
      • 2022-07-25
      • 1970-01-01
      • 2017-05-18
      • 1970-01-01
      • 2023-01-03
      • 1970-01-01
      相关资源
      最近更新 更多