I have two domain names (e.g. site1.com and site2.com) with CNAMES setup to run the blogs (e.g. blog.site1.com and blog.site2.com). On a separate server I am running VPS (NGINX) server with a mysql-server to run the two wordpress blogs.
The bests guidance I can find is at this link. However, they are using an Apache virtual host. So with Nginx I did the following:
cd /etc/nginx/sites-available
sudo cp default site1.com
sudo cp default site2.com
In the site1.com server block I modified the following:
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;
}
}
The similar changes were setup for site2.com nginx server block as well. Then symbolic links were setup for the ~/sites-enabled/ files. Then I changed the wp-config.php for each wordpress directory in site1.com and site2.com.
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');
When I navigate to either blog.site1.com or blog.site2.com I see the wordpress installation page.
The problem occurs after I complete the installation for one of the wordpress sites. Even though I have specified separate DB's for each wordpress install instance, both sites show the same wordpress instance. Since the wp-config.php file is clearly showing separate definitions, I am unsure where the error is. Could someone provide guidance for correcting this issue?
Nginx is a tricky beast. I would recommend removing the default_server
blocks and explicitly specifying IPs. I don't know why but in my experience nginx gets funky with multiple default servers or when you don't provide IP addresses.
I would not copy it directly as my rewrite conditional seems to be frowned upon by people who know what they are doing? Also I don't use fpm. Theres about 12 exact copies of this and all the domains load without issue.
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;
}
}