当WordPress位于子文件夹中时,无法访问管理员

时间:2019-10-19 18:06:29

标签: wordpress docker-compose traefik

我使用this Docker image安装了WordPress。我将WordPress安装在子文件夹(https://thibault.vlacich.fr/blog)中。

我正在使用Traefik进行路由。这是我的docker-compose文件:

version: '3.7'

networks:
  http_network:
    external: true
  thibaultvlacich:
    external: false

services:
  database:
    image: mariadb:latest
    command: ['--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci', '--default-authentication-plugin=mysql_native_password']
    volumes:
      - .docker/data/db:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
    networks:
      - thibaultvlacich

  wordpress:
    depends_on:
      - database
    image: wordpress:latest
    volumes:
      - ./wordpress/wp-content:/var/www/html/wp-content
    environment:
      WORDPRESS_DB_HOST: database:3306
      WORDPRESS_DB_USER: ${MYSQL_USER}
      WORDPRESS_DB_PASSWORD: ${MYSQL_PASSWORD}
      WORDPRESS_DB_NAME: ${MYSQL_DATABASE}
    labels:
      - traefik.enable=true
      - traefik.frontend.rule=Host:thibault.vlacich.fr;PathPrefix:/blog;PathPrefixStrip:/blog
      - traefik.port=80
      - traefik.docker.network=http_network
    networks:
      - thibaultvlacich
      - http_network

一切正常,除了管理员。当我转到https://thibault.vlacich.fr/blog/wp-admin时,我被重定向到https://thibault.vlacich.fr/wp-admin,然后无法访问管理员。

有什么主意我该如何解决? (WP_HOME和WP_SITEURL都正确设置为https://thibault.vlacich.fr/blog

4 个答案:

答案 0 :(得分:0)

我遇到了与您完全相同的问题。我已经进行了数周的故障排除工作,并弄丢了一半的头发,试图找出答案。我想我终于明白了。

在./wordpress/wp-content中创建一个名为blog的目录,并将所有数据移动到该目录中。然后使您的Docker组成类似于

version: '3.7'

networks:
  http_network:
    external: true
  thibaultvlacich:
    external: false

services:
  database:
    image: mariadb:latest
    command: ['--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci', '--default-authentication-plugin=mysql_native_password']
    volumes:
      - .docker/data/db:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
    networks:
      - thibaultvlacich

  wordpress:
    depends_on:
      - database
    image: wordpress:latest
    volumes:
      - ./wordpress/wp-content:/var/www/html/wp-content
    environment:
      WORDPRESS_DB_HOST: database:3306
      WORDPRESS_DB_USER: ${MYSQL_USER}
      WORDPRESS_DB_PASSWORD: ${MYSQL_PASSWORD}
      WORDPRESS_DB_NAME: ${MYSQL_DATABASE}
    labels:
      - traefik.enable=true
      - traefik.frontend.rule=Host:thibault.vlacich.fr;PathPrefix:/blog
      - traefik.port=80
      - traefik.docker.network=http_network
    working_dir: /var/www/html/wp-content/blog
    networks:
      - thibaultvlacich
      - http_network

现在它有一个奇怪的怪癖,因为您启动并运行后,我认为您不会遇到任何问题。首次配置wordpress网站时,您必须转到https://thibault.vlacich.fr/blog/blog进行安装过程。完成后,您应该可以转到https://thibault.vlacich.fr/blog并进行访问。我遇到了/ blog / wp-admin将重定向删除/ blog的问题,但现在没有。如果那不起作用,请告诉我,我将发布docker-compose.yml文件,您可以对其进行修改以匹配。

答案 1 :(得分:0)

我在docker-compose工作中发现了此配置。 通过将所有内容放在/ var / www / html / SUBFOLDER_NAME的子文件夹下 它解决了/wp-admin.php页面重定向的问题。

以下是wordpress的docker-compose部分,我的SUBFOLDER_NAME为'blog'。

# age                                wash.hands
#  34                             Before eating
#  19   Before eating, on public transportation
#  44               Before eating, After eating
#  22                              After eating
#  34 on public transportation, when I get home
#  12                             Before eating
#  54                           When I get home
#  63            When I get home, Before eating
#  23                  on public transportation

答案 2 :(得分:0)

嗨,我的 Traefik V2 解决方案

version: '3'

services:
  db:
    image: mysql:8.0
    container_name: blog_db
    restart: always
    env_file: .env
    environment:
      - MYSQL_DATABASE=blog
    volumes:
      - dbdata:/var/lib/mysql
    command: '--default-authentication-plugin=mysql_native_password'
    networks:
      - app-network

  wordpress:
    depends_on:
      - db
    build: .
    container_name: wordpress
    restart: always
    environment:
      WORDPRESS_DB_HOST: blog_db:3306
      WORDPRESS_DB_USER: $MYSQL_USER
      WORDPRESS_DB_PASSWORD: $MYSQL_PASSWORD
      WORDPRESS_DB_NAME: blog

    volumes:
      - ./wordpress:/var/www/html/blog
    networks:
      - app-network
      - proxy
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=proxy"
      - "traefik.http.routers.blog.entrypoints=websecure"
      - "traefik.http.routers.blog.rule=(Host(`example.com`) && PathPrefix(`/blog{regex:$$|/.*}`))"
      - "traefik.http.routers.blog.priority=10"
      - "traefik.http.services.blog.loadbalancer.server.port=80"
      - "traefik.http.routers.blog.tls=true"
      - "traefik.http.routers.blog.tls.certresolver=cloudflare"



volumes:
  dbdata:

networks:
  app-network:
    driver: bridge
  proxy:
    external: true

答案 3 :(得分:0)

或者,您可以在不创建子文件夹的情况下尝试此操作。尝试在 wp-config.php

中添加以下行
$_SERVER['REQUEST_URI'] = str_replace("/wp-admin/", "/blog/wp-admin/",  $_SERVER['REQUEST_URI']);