【问题标题】:Docker compose with nginx keeps displaying welcome to nginxDocker compose with nginx 一直显示欢迎使用 nginx
【发布时间】:2022-11-13 06:37:50
【问题描述】:

我正在尝试使用 docker-compose 和 nginx 设置一个 wordpress 环境。问题是我不能让 nginx 使用 wordpress index.php,即使我覆盖了 default.conf 并将我的 wordpress 文件结构安装到 /var/www/html。

这是 yml 文件的相关部分:

version: '3'

networks:
  wordpress:

services:
  site:
    platform: linux/arm64/v8
    build:
      context: .
      dockerfile: nginx.dockerfile
    container_name: nginx
    ports:
      - 8080:80
      - 8443:443
    volumes:
      - ./wordpress:/var/www/html:delegated
    depends_on:
      - php
      - mysql
    networks:
      - wordpress

在这里,我将 wordpress 文件夹安装到我使用 nginx.dockerfile 创建的 /var/www/html 文件夹中:

FROM nginx:stable-alpine

ADD ./nginx/default.conf /etc/nginx/conf.d/default.conf

RUN mkdir -p /var/www/html

这是我的 default.conf 文件:

upstream php {
    server unix:/tmp/php-cgi.socket;
    server php:9000;
}

server {
    listen 8080;
    listen [::]:8080;
    server_name localhost;

    root /var/www/html;

    index index.php;

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

    location ~ \.php$ {
        include fastcgi.conf;
        fastcgi_intercept_errors on;
        fastcgi_pass php;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires max;
        log_not_found off;
    }
}

server {
    listen 8443;
    listen [::]:8443;
    server_name localhost;

    root /var/www/html;

    index index.php;

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

    location ~ \.php$ {
        include fastcgi.conf;
        fastcgi_intercept_errors on;
        fastcgi_pass php;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires max;
        log_not_found off;
    }
}

我测试了什么:

Someone on stackoverflow 有同样的问题,答案似乎很清楚,但不幸的是它没有用。

运行docker-compose run --rm site cat /etc/nginx/conf.d/default.conf 时,它会打印我的default.conf 文件,并且我还确认带有index.php 的wordpress 结构位于文件夹/var/www/html 中。

我还测试了重命名配置文件,删除 docker 的缓存并从头开始重建所有内容,但 nginx 不在乎并加载它自己的配置文件。

Some people on Github 建议将 php 容器名称更改为 php-box1 之类的名称以避免混淆,但这也无济于事。

谢谢您的帮助。

【问题讨论】:

  • 您是否将 nginx 配置文件放在 /etc/nginx/sites-enabled 中?
  • 不,我正在覆盖/etc/nginx/conf.d/default.conf

标签: php wordpress docker nginx docker-compose


【解决方案1】:

所以我想通了。首先,如果仍然显示欢迎消息是因为浏览器的缓存。清除缓存后,我得到了ERR_EMPTY_RESPONSE。问题出在docker-compose.yml 文件中,为了将8080 端口绑定到80,我写了8080:80 而不是80:8080。我希望它会帮助那里的人。

【讨论】:

    猜你喜欢
    • 2018-11-15
    • 2023-03-06
    • 1970-01-01
    • 2012-02-05
    • 2017-10-31
    • 2021-10-26
    • 1970-01-01
    • 1970-01-01
    • 2014-02-23
    相关资源
    最近更新 更多