【问题标题】:How To Set Up Multiple WordPress Sites on a Single Ubuntu Instance with an Nginx VPS如何使用 Nginx VPS 在单个 Ubuntu 实例上设置多个 WordPress 站点
【发布时间】:2015-04-02 05:56:09
【问题描述】:

我有两个域名(例如 site1.com 和 site2.com),并设置了 CNAMES 来运行博客(例如 blog.site1.com 和 blog.site2.com)。在单独的服务器上,我正在运行带有 mysql-server 的 VPS (NGINX) 服务器来运行两个 wordpress 博客。

我能找到的最好的指导是link。但是,他们使用的是 Apache 虚拟主机。所以使用 Nginx 我做了以下事情:

cd /etc/nginx/sites-available

sudo cp default site1.com
sudo cp default site2.com

在 site1.com 服务器块中,我修改了以下内容:

server {
   listen 80 default_server;
   listen [::]:80 default_server ipv6only=on;

   #root /usr/share/nginx/html;
   root /home/ubuntu/www/blog.site1.com;         
   index index.php;

   server_name blog.site1.com;

   location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ /index.php;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # With php5-fpm:
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }
}

site2.com nginx 服务器块也设置了类似的更改。然后为 ~/sites-enabled/ 文件设置符号链接。然后我更改了 site1.com 和 site2.com 中每个 wordpress 目录的 wp-config.php。

site1.com (wp-config.php)

/** The name of the database for WordPress */
define('DB_NAME', 'FirstDatabase');

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

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

site2.com (wp-config.php)

/** The name of the database for WordPress */
define('DB_NAME', 'SecondDatabase');

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

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

当我导航到 blog.site1.com 或 blog.site2.com 时,我会看到 wordpress 安装页面。

在我完成其中一个 wordpress 站点的安装后出现问题。即使我为每个 wordpress 安装实例指定了单独的数据库,两个站点都显示相同的 wordpress 实例。由于 wp-config.php 文件清楚地显示了单独的定义,我不确定错误在哪里。有人可以提供纠正这个问题的指导吗?

【问题讨论】:

    标签: php mysql wordpress ubuntu nginx


    【解决方案1】:

    Nginx 是一个狡猾的野兽。我建议删除 default_server 块并明确指定 IP。我不知道为什么,但根据我的经验,nginx 在使用多个默认服务器或不提供 IP 地址时会变得很时髦。

    我不会直接复制它,因为我的重写条件似乎被知道他们在做什么的人不赞成?我也不使用fpm。大约有 12 个完全相同的副本,并且所有域都可以毫无问题地加载。

    server {
      listen 198.91.xx.xxx:80;
    
      server_name xxxxxx.org www.xxxxxx.org;
    
      access_log /home/xxxxxx/logs/xxxxxx.org.access.log;
      error_log /home/xxxxxx/logs/xxxxxx.org.error.log;
    
      root /home/xxxxxx/domains/xxxxxx.org/public_html/;
      index index.php index.html index.htm;
    
      if (!-e $request_filename) {
        rewrite ^/(.*)$ /index.php?q=$1 last;
      }
    
      # serve static files directly
      location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico)$ {
        expires           30d;
      }
    
      #location /indexlocation/ {
      #    autoindex on;
      #}
     location ~ .php$ {
        fastcgi_pass unix:/tmp/xxxxxx.socket;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
      }
    }
    

    【讨论】:

    • 我将 IP 添加到服务器块并删除了两个块中的所有默认配置(再次,两个外部域都显示相同的 wordpress 实例)。然后,我处理了您提供的示例,但是,nginx 重新加载失败。对于让两个 wordpress 实例在同一台服务器上工作,您还有其他建议吗?
    • 没有看到站点可用文件和 nginx.conf 文件,我不确定我可以提供多少帮助,但是我的主要怀疑是其中一个有问题,或者没有加载一个导致另一个用作默认值。没有真正的“Host 2 Wordpress”教程,它只是 2 个独立的域。如果您仍然遇到问题,我最好的建议是向 nginx 社区寻求帮助。 Nginx 不像 Apache 那样经常被小型团体或网站使用,因此在这里可以帮助您的人可能会更少。 forum.nginx.org/list.php?11
    猜你喜欢
    • 1970-01-01
    • 2018-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多