mysql - 一台主机上有多个 WordPress

标签 mysql wordpress nginx

我正在尝试在一台主机上部署多个 WordPress。我使用 nginx 将连接分配到好的子域。

我成功部署了第一个包含 WordPress 和 MySQL 的容器作为服务。使用此脚本:

version: '2'

services:
   db3:
     image: mysql:5.7
     volumes:
       - db_wp_lmt_data:/var/lib/mysql
     restart: always
     ports:
       - 3308:3306
       - 3308
     environment:
       MYSQL_ROOT_PASSWORD: FFFF
       MYSQL_DATABASE: DDDD
       MYSQL_USER: XXX
       MYSQL_PASSWORD: YYYY
   wordpress:
     depends_on:
       - db3
     image: wordpress:latest
     ports:
       - "8003:80"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db3:3306
       WORDPRESS_DB_USER: XXX
       WORDPRESS_DB_PASSWORD: YYYY
       VIRTUAL_HOST: ZZZZZ
     volumes:
       - wp_lmt_data:/var/www/html
volumes:
    db_wp_lmt_data:
    wp_lmt_data:
networks:
  default:
    external:
      name: nginxproxy_default

但是,当我使用相同的脚本添加第二个脚本时(将端口从 8003 更改为 8004,将 3308 更改为 3009 后),我遇到了一些麻烦。 mysql服务器可以从外部访问,但wordpress无法工作。当我从主机“curl -k localhost:8004”执行此操作时,它不会返回任何内容,而另一个 wordpress 返回主页内容。

我试图理解为什么它不起作用并解决它。但现在我不知道如何解决。

此外,我以附加模式启动了容器,一切看起来都很好:

db3_1        | 2017-12-27T23:50:45.558909Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
db3_1        | 2017-12-27T23:50:45.597390Z 0 [Note] mysqld (mysqld 5.7.20) starting as process 1 ...
db3_1        | 2017-12-27T23:50:45.612731Z 0 [Note] InnoDB: PUNCH HOLE support available
db3_1        | 2017-12-27T23:50:45.612804Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
db3_1        | 2017-12-27T23:50:45.612812Z 0 [Note] InnoDB: Uses event mutexes
db3_1        | 2017-12-27T23:50:45.612818Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
db3_1        | 2017-12-27T23:50:45.612824Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
db3_1        | 2017-12-27T23:50:45.612830Z 0 [Note] InnoDB: Using Linux native AIO
db3_1        | 2017-12-27T23:50:45.632121Z 0 [Note] InnoDB: Number of pools: 1
db3_1        | 2017-12-27T23:50:45.632384Z 0 [Note] InnoDB: Using CPU crc32 instructions
db3_1        | 2017-12-27T23:50:45.657365Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
db3_1        | 2017-12-27T23:50:45.722114Z 0 [Note] InnoDB: Completed initialization of buffer pool
db3_1        | 2017-12-27T23:50:45.735602Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
db3_1        | 2017-12-27T23:50:45.759510Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
db3_1        | 2017-12-27T23:50:45.798036Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
db3_1        | 2017-12-27T23:50:45.798748Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
db3_1        | 2017-12-27T23:50:45.873142Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
db3_1        | 2017-12-27T23:50:45.874746Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
db3_1        | 2017-12-27T23:50:45.874819Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
db3_1        | 2017-12-27T23:50:45.876036Z 0 [Note] InnoDB: Waiting for purge to start
db3_1        | 2017-12-27T23:50:45.926379Z 0 [Note] InnoDB: 5.7.20 started; log sequence number 12156537
db3_1        | 2017-12-27T23:50:45.928422Z 0 [Note] Plugin 'FEDERATED' is disabled.
db3_1        | 2017-12-27T23:50:45.932793Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
db3_1        | 2017-12-27T23:50:45.968083Z 0 [Note] InnoDB: Buffer pool(s) load completed at 171227 23:50:45
db3_1        | 2017-12-27T23:50:45.969521Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
db3_1        | 2017-12-27T23:50:45.973412Z 0 [Warning] CA certificate ca.pem is self signed.
db3_1        | 2017-12-27T23:50:45.976434Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
db3_1        | 2017-12-27T23:50:45.981110Z 0 [Note] IPv6 is available.
db3_1        | 2017-12-27T23:50:45.981787Z 0 [Note]   - '::' resolves to '::';
db3_1        | 2017-12-27T23:50:45.982192Z 0 [Note] Server socket created on IP: '::'.
db3_1        | 2017-12-27T23:50:45.989810Z 0 [Warning] 'user' entry 'root@localhost' ignored in --skip-name-resolve mode.
db3_1        | 2017-12-27T23:50:45.990490Z 0 [Warning] 'user' entry 'mysql.session@localhost' ignored in --skip-name-resolve mode.
db3_1        | 2017-12-27T23:50:45.990563Z 0 [Warning] 'user' entry 'mysql.sys@localhost' ignored in --skip-name-resolve mode.
db3_1        | 2017-12-27T23:50:45.990660Z 0 [Warning] 'db' entry 'performance_schema mysql.session@localhost' ignored in --skip-name-resolve mode.
db3_1        | 2017-12-27T23:50:45.990738Z 0 [Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
db3_1        | 2017-12-27T23:50:45.990805Z 0 [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
db3_1        | 2017-12-27T23:50:45.996112Z 0 [Warning] 'tables_priv' entry 'user mysql.session@localhost' ignored in --skip-name-resolve mode.
db3_1        | 2017-12-27T23:50:45.996739Z 0 [Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
db3_1        | 2017-12-27T23:50:46.021269Z 0 [Note] Event Scheduler: Loaded 0 events
db3_1        | 2017-12-27T23:50:46.022382Z 0 [Note] mysqld: ready for connections.
db3_1        | Version: '5.7.20'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)
db3_1        | 2017-12-27T23:50:46.022476Z 0 [Note] Executing 'SELECT * FROM INFORMATION_SCHEMA.TABLES;' to get a list of tables using the deprecated partition engine. You may use the startup option '--disable-partition-engine-check' to skip this check.
db3_1        | 2017-12-27T23:50:46.022543Z 0 [Note] Beginning of list of non-natively partitioned tables
db3_1        | 2017-12-27T23:50:46.069871Z 0 [Note] End of list of non-natively partitioned tables
wordpress_1  | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.18.0.6. Set the 'ServerName' directive globally to suppress this message
wordpress_1  | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.18.0.6. Set the 'ServerName' directive globally to suppress this message
wordpress_1  | [Wed Dec 27 23:50:46.370813 2017] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.25 (Debian) PHP/7.2.0 configured -- resuming normal operations
wordpress_1  | [Wed Dec 27 23:50:46.374367 2017] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'

感谢您的关注。

最佳答案

我终于找到了一种方法来做我想做的事。我删除了 docker-compose.yml 并从头开始。

我使用了这个脚本:

version: '2'

services:
    wordpress:
        image: wordpress
        links:
         - mariadb:mysql
        environment:
         - WORDPRESS_DB_PASSWORD=XXX
         - VIRTUAL_HOST= YYY
        ports:
         - "10001:80"
         - 10001
        expose:
         - 10001
        volumes:
         - mywordpressvolume:/var/www/html

    mariadb:
        image: mariadb
        environment:
         - MYSQL_ROOT_PASSWORD=XX
         - MYSQL_DATABASE=wordpress
        volumes:
         - mydbvolume:/var/lib/mysql

volumes:
    mywordpressvolume:
    mydbvolume:
    
networks:
  default:
    external:
      name: nginxproxy_default

这给了我一个可以运行的 WordPress。我仍然很困惑为什么 WordPress 有这种行为。也许由于某种原因 WordPress 无法访问数据库,我想知道使用服务名称上的链接是否是一个好习惯。然后,我使用了命令

docker exec mycontainername env | grep "VIRTU"

检查我的容器使用的所有 VIRTUAL_HOST 变量。最后,一切都结束了。

关于mysql - 一台主机上有多个 WordPress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48000129/

相关文章:

mysql - 获取 MySQL 表中每小时的整数总和

c# - 我可以在 Mysql 的一个连接字符串下创建多个不同的插入查询吗?

php - 使用自定义元键和元值扩展 wc_get_orders()

javascript - 将 PHP 插入 jQuery css()

wordpress - 在 WooCommerce 销售按钮中显示折扣百分比

MySQL IF ELSE 真假

nginx - 如何在openresty中更改body_filter_by_lua*中的内容长度

nginx - 在 Linux 服务器中设置 CDN

linux - Nginx 上的 Scalatra : how to set up?

mysql - 什么 MySQL 类型最适合 "price"列?