Docker-Wordpress-php-nginx-mysql-本地主机:80 502 错误网关错误

问题描述 投票:0回答:1

我以前在这里见过类似的问题和解决方案,但它们不是解决方案。我想使用 docker 在本地运行一个 WordPress 网站,但它不起作用。我得到“localhost没有发送任何数据ERR_EMPTY_RESPONSE”。我根据评论编辑了代码。现在我收到 502 Bad Gateway 错误。如果您能帮助我解决问题,我将不胜感激。您可以在本文末尾找到我的两个相关代码文件。

当我输入 docker-compose up -d 时,我得到输出:

docker-compose up -d

当我输入 docker-compose ps 时,我得到输出:

ps

码头工人:

dockerss

nginx.conf

    server {
    listen 80;
    server_name localhost;

    root /var/www/html;
    index index.php;


    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass wordpress:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

docker-compose.yml

 services:
  db:
    image: mysql:latest
    restart: always
    environment:
      MYSQL_DATABASE: wordpress_db
      MYSQL_USER: wp_user
      MYSQL_PASSWORD: wp_password
      MYSQL_ROOT_PASSWORD: '1'
    volumes:
      - db_data:/var/lib/mysql
    ports:
      - "3306:3306"

  wordpress:
    image: wordpress:latest
    restart: always
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_NAME: wordpress_db
      WORDPRESS_DB_USER: wp_user
      WORDPRESS_DB_PASSWORD: wp_password
    volumes:
      - wp_data:/var/www/html
    depends_on:
      - db
    ports:
      - "9000:9000"

  nginx:
    image: nginx:latest
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - wp_data:/var/www/html
      - ./nginx.conf:/etc/nginx/conf.d/default.conf
    depends_on:
      - wordpress

volumes:
  db_data:
  wp_data:
php wordpress docker nginx docker-compose
1个回答
0
投票

此设置将使用 Docker Compose 来编排容器。这是设置 WordPress 环境的综合指南:

使用 Nginx 和 MySQL 为 WordPress 构建 Docker Compose 设置

docker-compose.yml

services:
  wordpress:
    image: wordpress:latest
    restart: always
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: wordpress_user
      WORDPRESS_DB_PASSWORD: wordpress_pass
      WORDPRESS_DB_NAME: wordpress_db
    volumes:
      - wordpress_data:/var/www/html
    depends_on:
      - db

  db:
    image: mysql:latest
    restart: always
    environment:
      MYSQL_DATABASE: wordpress_db
      MYSQL_USER: wordpress_user
      MYSQL_PASSWORD: wordpress_pass
      MYSQL_RANDOM_ROOT_PASSWORD: '1'
    volumes:
      - db_data:/var/lib/mysql

  nginx:
    image: nginx:latest
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./nginx.conf:/etc/nginx/conf.d/default.conf
      - wordpress_data:/var/www/html
    depends_on:
      - wordpress

volumes:
  wordpress_data:
  db_data:

nginx.conf

server {
    listen 80;
    server_name localhost;

    root /var/www/html;
    index index.php;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass wordpress:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}
docker-compose up -d
http://localhost
© www.soinside.com 2019 - 2024. All rights reserved.