如何使用Nginx VPS在单个Ubuntu实例上设置多个WordPress站点

时间:2015-02-03 05:41:28

标签: php mysql wordpress ubuntu nginx

我有两个域名(例如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 / files设置了符号链接。然后我更改了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 Installation Page

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

1 个答案:

答案 0 :(得分:0)

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;
  }
}