【问题标题】:Wordpress Multisite Nginx Subdirectory Install Can No Longer Find DatabaseWordpress 多站点 Nginx 子目录安装无法再找到数据库
【发布时间】:2017-04-05 02:59:13
【问题描述】:

我在相当非标准的 wordpress 安装上设置多站点有点困难。 (我完全明白,如果我按照通常的方式进行操作,这一切都会完美无缺。我有限制。谢谢!)

我在非特权用户目录中使用 nginx 和 composer。

我已经使用 composer 成功建立了一个常规站点(这涉及在子目录中运行一个站点),如 here 所述。

效果很好,我可以使用 wordpress 作为依赖项,没有问题。

但是,当我尝试切换到多站点时,如 here 所述,Wordpress 不再能够连接到数据库,如下所示:Error establishing a database connection

没有错误写入 nginx 日志。

怀疑在子目录中运行多站点时,其他一些配置文件读取/使用wp-config.php 的方式有所不同,但我找不到任何文档。我是 wordpress 菜鸟,所以我可能没有找对地方。

请注意,当我注释掉时:

#define('SUBDOMAIN_INSTALL', false);
#define('DOMAIN_CURRENT_SITE', 'blog.mysite.com');
#define('PATH_CURRENT_SITE', '/wp/');
#define('SITE_ID_CURRENT_SITE', 1);
#define('BLOG_ID_CURRENT_SITE', 1);

我能够再次访问该站点,这告诉我 wordpress 仍然可以访问 wp-config.php,但其他一些东西无法使用我的数据库凭据。

我是否需要为某个子目录中的每个站点创建一个单独的 wp-config.php 文件?

我在下面列出了我认为相关的配置。如果需要,我们很乐意添加更多内容。

网站配置

  • Ubuntu 16.04.1 LTS
  • nginx 版本:nginx/1.10.0 (Ubuntu)
  • PHP 7.0.8-0ubuntu0.16.04.3 (cli) (NTS)
  • PHP-FPM 7.0.8-0ubuntu0.16.04.3 (fpm-fcgi)
  • 数据库服务器版本:10.0.27-MariaDB-0ubuntu0.16.04.1 Ubuntu 16.04

NGINX 配置

server {
    listen 80;
    listen [::]:80;
    # must have actual domain here, otherwise redirect can get funny
    server_name blog.mysite.com;
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl;
    root /home/blog/blog.mysite.com;
    index index.php index.html;
    autoindex off;
    charset off;
    try_files $uri $uri/ /index.php?$args;
    server_name blog.mysite.com;
    add_header Strict-Transport-Security "max-age=31536000";
    ssl on;
    ssl_certificate /etc/letsencrypt/live/blog.mysite.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/blog.mysite.com/privkey.pem;
    # prevent logjam attack
    # YOU MUST CREATE /etc/ssl/private/dhparams.pem FIRST! See instructions!
    ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/ssl/private/dhparams.pem;

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location / {
        # No php is touched for static content.
        # include the "?$args" part so non-default permalinks doesn't
        # break when using query string
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
        include fastcgi.conf;
        fastcgi_param HTTP_PROXY "";
        fastcgi_param HTTPS on;
        fastcgi_intercept_errors on;
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
    }

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

每个站点都有一个单独的配置文件。我希望我可能需要添加:

fastcgi_param SITE_ID_CURRENT_SITE 1;
fastcgi_param BLOG_ID_CURRENT_SITE 1;

或类似location ~ \.php$ 稍后指定实际站点,但那是 SWAG。

wp-config.php

<?php
/**
 * The base configuration for WordPress
 *
 * The wp-config.php creation script uses this file during the
 * installation. You don't have to use the web site, you can
 * copy this file to "wp-config.php" and fill in the values.
 *
 * This file contains the following configurations:
 *
 * * MySQL settings
 * * Secret keys
 * * Database table prefix
 * * ABSPATH
 *
 * @link https://codex.wordpress.org/Editing_wp-config.php
 *
 * @package WordPress
 */

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'foo');

/** MySQL database username */
define('DB_USER', 'bar');

/** MySQL database password */
define('DB_PASSWORD', 'superextrasecret');

/** MySQL hostname */
define('DB_HOST', 'localhost');

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');

/* moving stuff out of the main directory */
define( 'WP_CONTENT_DIR', dirname(__FILE__) . '/wp-content');
define( 'WP_PLUGIN_URL', dirname(__FILE__) . 'https://blog.mysite.com/wp/wp-content');

define( 'WP_PLUGIN_DIR', dirname(__FILE__) . '/wp-content/plugins');
define( 'WP_PLUGIN_URL', dirname(__FILE__) . 'https://blog.mysite.com/wp/wp-content/plugins');

/**#@+
 * Authentication Unique Keys and Salts.
 *
 * Change these to different unique phrases!
 * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
 * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
 *
 * @since 2.6.0
 */
define('AUTH_KEY',         'foo');
define('SECURE_AUTH_KEY',  'bar');
define('LOGGED_IN_KEY',    'bat');
define('NONCE_KEY',        'baz');
define('AUTH_SALT',        'quux');
define('SECURE_AUTH_SALT', 'corge');
define('LOGGED_IN_SALT',   'grault');
define('NONCE_SALT',       'garply');
/**#@-*/

/**/

/**
 * WordPress Database Table prefix.
 *
 * You can have multiple installations in one database if you give each
 * a unique prefix. Only numbers, letters, and underscores please!
 */
$table_prefix  = 'wp_';

/**
 * For developers: WordPress debugging mode.
 *
 * Change this to true to enable the display of notices during development.
 * It is strongly recommended that plugin and theme developers use WP_DEBUG
 * in their development environments.
 *
 * For information on other constants that can be used for debugging,
 * visit the Codex.
 *
 * @link https://codex.wordpress.org/Debugging_in_WordPress
 */
define('WP_DEBUG', true);

/* multisite settings */
define('WP_ALLOW_MULTISITE', true);
define('SUBDOMAIN_INSTALL', false);
define('DOMAIN_CURRENT_SITE', 'blog.mysite.com');
define('PATH_CURRENT_SITE', '/wp/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);

/** Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
    define('ABSPATH', dirname(__FILE__) . '/wp');

/** Sets up WordPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php');

/* That's all, stop editing! Happy blogging. */

index.php

<?php
/**
 * Front to the WordPress application. This file doesn't do anything, but loads
 * wp-blog-header.php which does and tells WordPress to load the theme.
 *
 * @package WordPress
 */

/**
 * Tells WordPress to load the WordPress theme and output it.
 *
 * @var bool
 */
define('WP_USE_THEMES', true);

/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . '/wp/wp-blog-header.php' );

目录布局

~/blog.mysite.com$
    composer.json
    composer.lock 
    index.php
    README.md
    vendor
    wp
    wp-config.php
    wp-content

wp_blogs

+---------+---------+--------------------+------+---------------------+---------------------+--------+----------+--------+------+---------+---------+
| blog_id | site_id | domain             | path | registered          | last_updated        | public | archived | mature | spam | deleted | lang_id |
+---------+---------+--------------------+------+---------------------+---------------------+--------+----------+--------+------+---------+---------+
|       1 |       1 | blog.mysite.com   | /wp/ | 2016-11-21 15:00:30 | 0000-00-00 00:00:00 |      1 |        0 |      0 |    0 |       0 |       0 |
+---------+---------+--------------------+------+---------------------+---------------------+--------+----------+--------+------+---------+---------+

【问题讨论】:

  • 我认为您的 wp-config 缺少一个常量。没有定义define('MULTISITE', true);。在define('WP_ALLOW_MULTISITE', true); 之后添加
  • 嗯,这太丢人了。所有这一切都是失败的copypasta。如果您想将其添加为答案,我一定会接受!
  • 是的,太好了。一点也不丢人——我检查这些常数的原因是我过去曾犯过那个确切的问题!它们看起来很相似,以至于你可能会错过一个。

标签: wordpress nginx composer-php


【解决方案1】:

我认为您的 wp-config 缺少一个常量。没有:

define('MULTISITE', true);

已定义。

在后面加上:

define('WP_ALLOW_MULTISITE', true);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-15
    • 2015-05-21
    • 2018-10-28
    • 2011-09-08
    • 1970-01-01
    • 2016-03-24
    相关资源
    最近更新 更多