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

Php 如何使用Nginx VPS在一个Ubuntu实例上设置多个WordPress站点,php,mysql,wordpress,ubuntu,nginx,Php,Mysql,Wordpress,Ubuntu,Nginx,我有两个域名(例如site1.com和site2.com)和CNAMES设置来运行博客(例如blog.site1.com和blog.site2.com)。在一个单独的服务器上,我运行VPS(NGINX)服务器和一个mysql服务器来运行两个wordpress博客 我能找到的最好的指导就是这个。但是,他们使用的是Apache虚拟主机。因此,对于Nginx,我做了以下工作: cd /etc/nginx/sites-available sudo cp default site1.com sudo c

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

我能找到的最好的指导就是这个。但是,他们使用的是Apache虚拟主机。因此,对于Nginx,我做了以下工作:

cd /etc/nginx/sites-available

sudo cp default site1.com
sudo cp default site2.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;
    }
}
在site1.com服务器块中,我修改了以下内容:

cd /etc/nginx/sites-available

sudo cp default site1.com
sudo cp default site2.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)

site2.com(wp config.php)

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


问题发生在我完成wordpress站点之一的安装之后。尽管我为每个wordpress安装实例指定了单独的DB,但两个站点都显示相同的wordpress实例。由于wp-config.php文件清楚地显示了单独的定义,我不确定错误在哪里。有人能为纠正这个问题提供指导吗

Nginx是一只狡猾的野兽。我建议删除
default\u服务器
块并显式指定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文件的情况下,我不确定还能提供多少帮助,但是我的主要怀疑是其中一个出现了问题,或者没有加载一个导致另一个被用作默认设置。没有真正的“主机2 Wordpress”教程,它只是两个独立的域。如果您仍然有问题,我最好的建议是向nginx社区寻求帮助。Nginx不像Apache那样经常被小型团体或网站使用,因此在这里可以帮助您的人可能会更少。