简体   繁体   English

Docker Wordpress 站点中的 URL 问题

[英]URL issue in Docker Wordpress site

I wanted to create a local dev environment for a wordpress site using docker.我想使用 docker 为 wordpress 站点创建一个本地开发环境。 So I have the following docker-compose file :所以我有以下 docker-compose 文件:

version: '3'

services:
  db:
    image: mariadb
    restart: on-failure
    environment:
    - MYSQL_DATABASE=${WP_DB_NAME}
    - MYSQL_USER=${WP_DB_USER}
    - MYSQL_PASSWORD=${WP_DB_USER_PASSWORD}
    volumes:
    #- ./db_data:/var/lib/mysql
    - ./mysql_dump/backup.sql:/docker-entrypoint-initdb.d/backup.sql
    - ./mysql_dump/migrate.sql:/docker-entrypoint-initdb.d/migrate.sql
    networks:
    - local

  wordpress:
    image: wordpress
    depends_on:
    - db
    restart: always
    ports:
      - 8080:80
    environment:
    - WORDPRESS_DB_HOST=db
    - WORDPRESS_DB_USER=${WP_DB_USER}
    - WORDPRESS_DB_PASSWORD=${WP_DB_USER_PASSWORD}
    - WORDPRESS_DB_NAME=${WP_DB_NAME}
    volumes: 
    - ./htdocs:/var/www/html
    networks:
      local:
        ipv4_address: 172.23.0.4

networks:
  local:
    driver: bridge
    ipam:
      config:
      - subnet: 172.23.0.0/24

I use volume to start mariadb with existing database dump.我使用 volume 来启动带有现有数据库转储的 mariadb。

Website is loading fine, but some URLs are wrong :网站加载正常,但有些 URL 错误:

  • When I try to connect, I am redirected to : http://172.23.0.4/172.23.0.4/wp-admin/ for example当我尝试连接时,我被重定向到:例如http://172.23.0.4/172.23.0.4/wp-admin/
  • Some js scripts are also not loaded due to wrong URLs like http://172.23.0.4172.23.0.4/wp-includes/js/tinymce/tinymce.min.js?ver=4920-20181217一些 js 脚本也因为错误的 URL 而没有加载,比如http://172.23.0.4172.23.0.4/wp-includes/js/tinymce/tinymce.min.js?ver=4920-20181217

I checked the general settings in the admin panel, and the values siteurl and home in the database and they are correct : 172.23.0.4 .我检查了管理面板中的常规设置,以及数据库中的siteurlhome值,它们是正确的: 172.23.0.4 The website in production (no docker but classic LAMP install) is working fine by the way…顺便说一下,生产中的网站(没有 docker 但经典的 LAMP 安装)运行良好……

Do you have any hints ?你有什么提示吗? (I'm not that familiar with web development, especially with wordpress) (我对 web 开发不太熟悉,尤其是 wordpress)

Looks like specifying 172.23.0.4 in wordpress settings for home and siteurl is somehow (don't know why though) causing the issue.看起来在homesiteurl wordpress 设置中指定172.23.0.4不知何故(虽然不知道为什么)导致了这个问题。 Instead, setting the value to http://172.23.0.4 fixed the problem.相反,将值设置为http://172.23.0.4解决了问题。

If someone has some explanation, please tell me.如果有人有一些解释,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM