Wordpress3.9开启多网站配置配置nginx进行局域网測试.

由于须要帮staff迁移一些数据, 所以想到了使用wordpress的多网站. 这个功能在wordpress3.0后就有了.

软件系统等信息:  OS: linux debian wheezy

php:5.4.4-14

mysql:5.5.37

server:nginx1.2.1 /apache 2.2.2

首先下载wordpress3.9, 安装的时候, 须要注意一下 我的www文件夹是/home/www, 所在把wordpress的路径是 /home/www/wordpress 

我的nginx默认没有配置不论什么东西, 所以直接浏览器输入

127.0.0.1/wordpress/wp-admin/install.php 就能够安装了. 可是这里不能这样, 由于多网站基于localhost的nginx rewrite是无效的, 所以这里我们须要先配置nginx的虚拟主机.

在debian里面, nginx的配置文件是/etc/nginx/nginx.conf 来管理全局的. 在/etc/nginx/site-available 和/etc/nginx/conf.d 是用来管理虚拟主机的

这里我们新建一个叫wp的文件 在/etc/nginx/site-available/wp

#touch /etc/nginx/site-available/wp

增加以下的内容, 注意这里我们是有用的基于域名的.

{
    listen 80;
    server_name wp.com www.wp.com *.wp.com;
    charset utf-8;
    index index.html index.htm index.php;
    root /home/www/wordpress;

    location / {
        autoindex on;
        autoindex_exact_size on;
        autoindex_localtime on;
        index index.php index.html;
        if (!-f $request_filename) {
            rewrite ^(.*)$ /index.php?

_rp_=$1 last; break; } } location ~ .*.(git|jpg|jpeg|png|bmp|swf)$ { expires 1d; } location ~ .*.(js|css)?$ { expires 12h; } location ~ .php$ { fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /home/www/wordpress$fastcgi_script_name; include fastcgi_params; } location /doc/ { alias /usr/share/doc/; autoindex on; allow 127.0.0.1; allow ::1; deny all; } }

然后由于是本地測试, 所以须要改动上面的server name的hosts

#vim /etc/hosts

添加以下一行在hosts里面

127.0.0.1 *.wp.com www.wp.com wp.com

接着重载入下nginx

#nginx -t 測试通过然后重载入

#/etc/init.d/nginx reload

如今用wp.com 就能够訪问初始的wordpress安装界面了

附上子域名和子文件夹的apache配置 

define('SUBDOMAIN_INSTALL', false); false是子文件夹, true是子域名 (子文件夹訪问是通过http://xxx.com/网站2 网站来的, 子域名是通过http://网站2.www.com来訪问的)

子域名的

RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
 
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
 
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*.php)$ $1 [L]
RewriteRule . index.php [L]

子文件夹的 

RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*.php)$ $2 [L]
RewriteRule . index.php [L]

原文地址:https://www.cnblogs.com/tlnshuju/p/6979032.html