连接存在nginx容器和新的wordpress容器的问题

时间:2019-02-05 19:25:14

标签: wordpress docker nginx docker-compose

nginx容器对我有用。效果很好。但是现在我需要从另一个docker-compose.yml文件中使用WordPress添加一个新容器。

创建新容器后,我的站点无法从端口80运行,并显示错误502 Bad Gateway。端口8000可以正常工作。

wordpres-docker-compose.yml

version: '3.7'
services:
  db:
    image: mysql:5.7
    container_name: mysql_5_7
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    env_file:
      - ./.env
    environment:
      MYSQL_ROOT_PASSWORD: ${ROOT_PASSWORD}
      MYSQL_DATABASE: ${DB_NAME}
      MYSQL_USER: ${DB_USER}
      MYSQL_PASSWORD: ${DB_PASSWORD}
    networks:
      - app-network

  wordpress:
    image: wordpress:latest
    container_name: my_site
    depends_on:
      - db
    networks:
      - app-network
    ports:
      - "8000:80"
    volumes:
      - ./:/var/www/html
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_NAME: ${DB_NAME}
      WORDPRESS_DB_USER: ${DB_USER}
      WORDPRESS_DB_PASSWORD: ${DB_PASSWORD}

networks:
  app-network:
    external: true

volumes:
  db_data:

nginx-docker-compose.yml

version: '3'
services:
  nginx:
    image: nginx:latest
    container_name: docker_nginx
    restart: unless-stopped
    tty: true
    volumes:
      - ./conf.d/:/etc/nginx/conf.d/
      - /home/user/www/:/usr/local/www/
    ports:
      - 80:80
      - 443:443
    external_links:
      - my_site
    networks:
      - app-network

networks:
  app-network:
    external: true

site-nginx.conf

upstream mysite{
  server site:8000;
}

server {
        listen 0.0.0.0:80;
        server_name www.site.com site.com;

        access_log /usr/local/www/site/log/nginx.access.log;
        error_log /usr/local/www/site/log/nginx.error.log;

        location / {
                proxy_pass http://mysite;
                client_max_body_size 100M;
        }
}

2 个答案:

答案 0 :(得分:0)

由于您定义的server site:8000;,我认为site-nginx.conf文件中的server my_site:8000;应该是container_name

答案 1 :(得分:0)

需要释放所有不带端口的嵌套应用。