Wordpress Multisite Nginx子目录安装不再能够查找数据库

时间:2016-11-21 16:27:38

标签: wordpress nginx composer-php

我在一个非标准的wordpress安装上设置多站点有点困难。 (我完全理解,如果我按照通常的方式做到这一点,这一切都会完美无缺。我有约束。谢谢!)

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

我已成功使用composer设置常规网站(包括在子目录中运行网站),如here所述。

效果很好,我能够使用wordpress作为依赖,没有问题。

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

没有错误写入nginx日志。

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

请注意,当我发表评论时:

#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)
  • DB Server版本: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 |
+---------+---------+--------------------+------+---------------------+---------------------+--------+----------+--------+------+---------+---------+

1 个答案:

答案 0 :(得分:1)

我认为你的wp-config缺少常量。没有;

define('MULTISITE', true); defined.

之后添加;

define('WP_ALLOW_MULTISITE', true);
相关问题