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]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值