【问题标题】:Docker Wordpress/Apache behind Docker Nginx - Port Number IssueDocker Nginx 背后的 Docker Wordpress/Apache - 端口号问题
【发布时间】:2021-05-09 09:20:22
【问题描述】:

我在让 wordpress docker 镜像与 nginx docker 镜像一起工作时遇到问题。

python/django 容器与 nginx 完美配合,但 wordpress/apache 有问题。我可以使用 https 访问 django 站点。我无法使用 https 进入 wordpress 之一。事实上,当我访问我的站点 site.com/wp 时,我会返回 site.com:8080/wp,所以由于某种原因它是通过端口返回的8080,而不是 44380。我尝试将 wordpress 站点设置为根位置 /(在 default.conf 文件中),但仍然存在同样的问题(然后我得到 site.com:8080)。 wordpress 功能正常,我可以照常编辑网站。

nginx 的 default.conf 文件

disable_symlinks off;
ssl_certificate xxx
ssl_certificate_key xxx

server {
    listen 80;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    server_name site.com;

    location / {
        proxy_pass http://django:8000; #django container
    }

    location /static {
        alias /path/to/static;
    }

    location /wp {
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;        
        proxy_pass http://wordpress:80; #the wordpress container
    }
}

码头工人 yml

version: '3.7'

services:
  django:
    restart: always
    build: 
      context: .
      dockerfile: docker-django #django gunicorn server, python image
    ports:
      - "8000:8000"

  wordpress:
    restart: always
    build:
      context: .
      dockerfile: docker-wordpress #docker wordpress-apache image
    # image: wordpress:latest
    volumes:
      - ./www/html:/var/www/html
      - ./etc/apache2:/etc/apache2
    ports:
      - "8080:80"

  nginx:
    restart: always
    build: 
      context: .
      dockerfile: docker-nginx #docker nginx image
    # image: nginx
    volumes:
      - ./xx/static:/usr/xx/static
      - ./nginx/conf.d:/etc/nginx/conf.d
    ports:
      - "443:443"
      - "80:80"
    depends_on:
      - django
      - wordpress

【问题讨论】:

    标签: django wordpress docker nginx


    【解决方案1】:

    似乎 wordpress 容器正在从 mysql 中提取 8080 端口号,我最初将它设置为本地测试。

    通过将这些行添加到 wp-config.php 来覆盖 mysql 存储的站点名称对我有用

    define( 'WP_HOME', 'https://' . $_SERVER['HTTP_HOST'] . '/' );
    define( 'WP_SITEURL', 'https://' . $_SERVER['SERVER_NAME'] . '/' );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-31
      • 2022-11-03
      • 2019-06-01
      • 2020-06-09
      • 1970-01-01
      • 2022-11-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多