Docker-Wordpress-php-nginx-mysql-本地主机:8080 ERR_EMPTY_RESPONSE

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

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

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

docker-compose up -d

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

ps

码头工人:

dockerss

nginx.conf

server {
listen 8080;

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

server_name localhost;

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

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

location ~ /\.ht {
    deny all;
}}

docker-compose.yml

services:


db:
    image: mysql:8
    container_name: wordpress_db
    restart: always
    environment:
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wp_user
      MYSQL_PASSWORD: wp_password
      MYSQL_ROOT_PASSWORD: root_password
    volumes:
      - db_data:/var/lib/mysql

  wordpress:
    image: wordpress:php7.4-fpm
    container_name: wordpress_php
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_NAME: wordpress
      WORDPRESS_DB_USER: wp_user
      WORDPRESS_DB_PASSWORD: wp_password
    volumes:
      - wp_data:/var/www/html

  nginx:
    image: nginx:latest
    container_name: wordpress_nginx
    restart: always
    ports:
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.