dongxikuo5171 2015-02-03 05:41
浏览 63

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

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.

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?

  • 写回答

1条回答 默认 最新

  • duanquyong8164 2015-02-03 06:54
    关注

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

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100