错误28:返回首页在Docker中使用nginx反向代理时,10000毫秒后解析超时(http_request_failed)

wtlkbnrh  于 2023-03-01  发布在  Nginx
关注(0)|答案(2)|浏览(156)

我试图设置一个本地WordPress环境使用Docker合成与Nginx反向代理。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;
    }

}

本地域在本地解析为/etc/hosts中的www.example.com我没有使用HTTPS(只是HTTP)来简化测试。127.0.0.1 in /etc/hosts I'm not using HTTPS (just HTTP) to simplify the test.
谢谢!

dtcbnfnu

dtcbnfnu1#

我有同样的问题,WordPress容器无法到达公共IP地址上的网站,由于Docker网络。
最好的解决方案是将fqdn别名添加到docker-compose.yml文件中的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
ecfdbz9o

ecfdbz9o2#

我有同样的问题,并发现这是因为名称解析是时髦的根域,由于分裂DNS我运行。
添加extra_hosts为我修复了它

...
   wordpress:
     image: wordpress:latest
     ports:
       - 8080:80
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: xxxxxxx
       WORDPRESS_DB_PASSWORD:xxxxxx
       WORDPRESS_DB_NAME: wordpressdb
     extra_hosts:
       - mydomain.com:internal or external loopback IP has needed
       - www.mydomain.com:internal or external loopback IP has needed
       - blog.mydomain.com:internal or external loopback IP has needed
...

相关问题