WordPress从Apache迁移到Nginx过程

来源:互联网 发布:聊天使用什么网络库 编辑:程序博客网 时间:2024/04/29 18:17

WordPress从Apache迁移到Nginx过程

代码迁移

  1. 使用git上传然后clone,方便以后的管理还有迁移
  2. 直接打包,然后在另外的一台机子上wget下来

使用打包的方式

  • 打包

    tar -zcvf wordpress.tar.gz --exclude=wordpress/.git cqc
  • 把打包好的文件放在服务器能不访问的文件夹里面,在另外的一台机子的终端

    wget http://xxx.xxx.xxx.xxx/wordpress.tar.gz
  • 解压

    tar zxvf wordpress.tar.gz

数据库迁移

把数据库导出来,导入到另外的机器上就行

数据库用二者的phpmyadmin导出和上传即可。我导出 .sql 文件,大小为9M,而phpMyAdmin的上传限制大小是2M,怎么办?其实我们可以压缩 .sql 文件为 zip格式,压缩之后就有了1.4M了,分分钟完成上传。要知道 phpMyAdmin 可是支持 .sql.zip 文件的。

配置vhosts

apache 在wordpress上在使用了伪静态,所有在nginx上也要使用伪静态

ubuntu 在 /etc/nginx 目录下可以新建一个 vhosts文件夹。在这里我们要解析 wordpress 目录,那么我就新建一个 wordpress.conf 文件。

现在例如我要把 blog.cuiqingcai.com 解析到 wordpress 文件夹,配置如下

server {    listen 80;    server_name cuiqingcai.com blog.cuiqingcai.com;    index index.html index.htm index.php;    root /var/www/cqc;    location / {        if (!-e $request_filename) {            rewrite ^([_0-9a-zA-Z-]+)?(/wp-.*) $2 last;            rewrite ^([_0-9a-zA-Z-]+)?(/.*\.php)$ $2 last;            rewrite ^ /index.php last;        }    }    location ~ \.php$ {        fastcgi_pass 127.0.0.1:9000;    #    # With php5-fpm:    #    fastcgi_pass unix:/var/run/php5-fpm.sock;        fastcgi_index index.php;        fastcgi_param SCRIPT_FILENAME /var/www/cqc$fastcgi_script_name;        include fastcgi_params;    }}

之后在 /etc/nginx/nginx.conf 中的 http{} 中添加一行

include /etc/nginx/vhosts/cqc.conf;
  • 我配置二级项目的时候使用如下配置 vi /etc/nginx/conf.d/default.conf

    server {    listen       80;    server_name  www.biyongyao.com;    charset utf-8;    access_log  /var/log/nginx/access.log  main;    #root   /usr/share/nginx/html/wordpress;    root   /home/biyongyao/www/wordpress;    index  index.php index.html index.htm;     location / {        try_files $uri $uri/ =404;        if (!-e $request_filename) {           rewrite ^([_0-9a-zA-Z-]+)?(/wp-.*) $2 last;           rewrite ^([_0-9a-zA-Z-]+)?(/.*\.php)$ $2 last;           rewrite ^ /index.php last;        }    }    location /ed2k/ {        if (!-e $request_filename){           rewrite  ^/ed2k/(.*)$  /ed2k/index.php?s=/$1  last;        }    }    location /MobileShop/ {        if (!-e $request_filename){           rewrite  ^/MobileShop/(.*)$  /MobileShop/index.php?s=/$1  last;        }    }    error_page  404              /404.html;    # redirect server error pages to the static page /50x.html    #    error_page   500 502 503 504  /50x.html;    location = /50x.html {        root   /usr/share/nginx/html;    }    location ~ \.php$ {        try_files $uri =404;        fastcgi_pass 127.0.0.1:9000;        fastcgi_index index.php;        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;        include fastcgi_params;    }}

原文地址:http://biyongyao.com/archives/225

阅读全文
0 0