草根吧论坛部署恢复

第1章 系统环境说明

1.1 部署环境说明

1.1.1 系统准备环境

[root@function ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
[root@function ~]# uname -r
3.10.0-693.el7.x86_64
[root@caogenba ~]# ifconfig
inet 192.168.10.135 netmask 255.255.255.0 broadcast 192.168.10.255
[root@caogenba ~]# echo $LANG
en_US.UTF-8

1.1.2 程序版本说明

程序名称 版本 说明
MySQL 5.7.23 源程序数据库可能为5.6.30
PHP 5.6.35 php版本必须7.0以下
Nginx 1.14.0
Nativcat 12.1.12

1.1.3 程序部署说明

LNMP均部署在同一台服务器上,关闭防火墙和SELinux。

1.2 参考文档

https://www.cnblogs.com/hnxxcxg/p/7610582.html

http://www.pexxw.cn/jzbj/567.html

https://www.cnblogs.com/luowei/p/6496976.html

https://www.dfbazhu.com/thread-1609-1-1.html

http://www.discuz.net/thread-3099350-1-1.html

第2章 CentOS7部署草根吧

2.1 部署LNMP环境

可参考之前的几篇文章《MySQL数据库多种安装方法介绍》《LNMP环境之PHP》《编译安装Nginx》

2.2 使用nativcat还原数据库

2.2.1 创建授权用户

[root@caogenba ~]# mysql -uroot -p
# 给草根吧论坛授权
mysql> grant ALL on caogen8.* to 'caogenba'@'%' identified by 'caogenba';

# 给草根吧源码站授权
mysql> grant ALL on cgzzn.* to 'caogenba'@'%' identified by 'caogenba';

2.2.2 使用caogenba用户登陆mysql

图片[1]|草根吧论坛部署恢复|leon的博客

2.2.3 创建数据库

图片[2]|草根吧论坛部署恢复|leon的博客图片[3]|草根吧论坛部署恢复|leon的博客

Tips:其他站点的数据库字符集和排序规则均使用此种方式。

2.2.4 连接还原数据库

图片[4]|草根吧论坛部署恢复|leon的博客

Tips:草根吧论坛数据库还原后会提示一些时间无法插入和一个视图pre_it168_wike_postview1不存在的错误,可以直接忽略,应该不影响后续使用。

2.3 配置web程序

2.3.1 上传web程序

上传程序到/usr/local/nginx/html/目录下,并重命名为caogenba和cgzzn。

2.3.1.1 上传草根吧论坛站点

[root@caogenba ~]# mv web /usr/local/nginx/html/caogenba
[root@caogenba ~]# chown -R nginx.nginx /usr/local/nginx/html/caogenba

2.3.1.2 上传草根吧源码站站点

[root@caogenba ~]# mv web /usr/local/nginx/html/cgzzn
[root@caogenba ~]# chown -R nginx.nginx /usr/local/nginx/html/cgzzn

2.3.2 编辑站点配置文件

2.3.2.1 编辑草根吧论坛配置文件

[root@caogenba ~]# cd /usr/local/nginx/html/caogenba/

[root@caogenba caogenba]# vim config/config_global_default.php
163 $_config['admincp']['checkip'] = 0; // 此处将1修改为0

[root@caogenba caogenba]# vim config/config_global.php
// 修改数据库连接信息
10 $_config['db']['1']['dbhost'] = 'localhost';
11 $_config['db']['1']['dbuser'] = 'caogenba';
12 $_config['db']['1']['dbpw'] = 'caogenba';
15 $_config['db']['1']['dbname'] = 'caogen8';
//可根据实际情况修改为自己域名,此处使用默认值
64 $_config['cookie']['cookiedomain'] = '.caogen8.co';
// 防止无法登陆管理后台或自动推出后台
103 $_config['admincp']['checkip'] = '0';
// 注释下面关于CDN使用的参数
125 /*$_config['extend']['storage']['curstorage'] = 'qiniu';
126 $_config['extend']['storage']['qiniu']['accesskey'] = '七牛accesskey';
127 $_config['extend']['storage']['qiniu']['secretkey'] = '七牛secretkey';
128 $_config['extend']['storage']['qiniu']['attachurl'] = 'http:// 七牛attachurl';
129 $_config['extend']['storage']['qiniu']['bucket'] = '七牛bucket';
130 $_config['extend']['storage']['qiniu']['imgprocessor'] = '!preview';
131
132
133 $_config['mirror_cdn'] = "http://你的URL";
134 */

[root@caogenba caogenba]# vim config/config_ucenter.php
// 修改数据库连接信息
6 define('UC_DBHOST', 'localhost');
7 define('UC_DBUSER', 'caogenba');
8 define('UC_DBPW', 'caogenba');
9 define('UC_DBNAME', 'caogen8');
11 define('UC_DBTABLEPRE', '`caogen8`.pre_ucenter_');
// 修改UC配置
16 define('UC_API', 'http://www.caogen8.co/uc_server');
18 define('UC_IP', '192.168.10.135');

[root@caogenba caogenba]# vim uc_server/data/config.inc.php
// 修改数据库连接信息
2 define('UC_DBHOST', 'localhost');
3 define('UC_DBUSER', 'caogenba');
4 define('UC_DBPW', 'caogenba');
5 define('UC_DBNAME', 'caogen8');

2.3.2.2 编辑草根吧源码站配置文件

[root@caogenba ~]# cd /usr/local/nginx/html/cgzzn/

[root@caogenba cgzzn]# vim config/config_global_default.php
163 $_config['admincp']['checkip'] = 0; // 此处将1修改为0

[root@caogenba cgzzn]# vim config/config_global.php
// 修改数据库连接信息
10 $_config['db']['1']['dbhost'] = 'localhost';
11 $_config['db']['1']['dbuser'] = 'caogenba';
12 $_config['db']['1']['dbpw'] = 'caogenba';
15 $_config['db']['1']['dbname'] = 'cgzzn';
// 防止无法登陆管理后台或自动推出后台
93 $_config['admincp']['checkip'] = 0;

[root@caogenba cgzzn]# vim config/config_ucenter.php
// 修改数据库连接信息
6 define('UC_DBHOST', 'localhost');
7 define('UC_DBUSER', 'caogenba');
8 define('UC_DBPW', 'caogenba');
9 define('UC_DBNAME', 'cgzzn');
11 define('UC_DBTABLEPRE', '`cgzzn`.pre_ucenter_');
// 修改UC配置
16 define('UC_API', 'http://www.cgzzn.com/uc_server');
18 define('UC_IP', '192.168.10.135');

[root@caogenba cgzzn]# vim uc_server/data/config.inc.php
// 修改数据库连接信息
3 define('UC_DBHOST', 'localhost');
4 define('UC_DBUSER', 'caogenba');
5 define('UC_DBPW', 'caogenba');
6 define('UC_DBNAME', 'cgzzn');

2.3.3 修改相关文件防止无法登陆后台

# 仅草根吧论坛进行修改
[root@caogenba caogenba]# vim admin.php
// 注释以下内容
30 /*if(!$_G['uid'] || !getstatus($_G['member']['allowadmincp'], 1)) {
31 header('Location: /');
32 }*/
[root@caogenba caogenba]# vim uc_server/admin.php
// 在文件首行添加此行,防止web页面出现乱码
<? PHP header("content-Type: text/html;charset=gbk"); ?>

# 两个站点均需要修改
[root@caogenba caogenba/cgzzn]# vim uc_server/model/misc.php
// 修改68行如下所示
68 $port = !empty($matches['port']) ? $matches['port'] : ($matches['scheme'] == 'https' ? 443 : 80);
// 添加以下代码段
70 if(substr($url,0,5)=='https'){
71 $ch = curl_init($url);
72 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
73 if($post){
74 curl_setopt($ch, CURLOPT_POST, 1);
75 curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
76 }
77 if($cookie){
78 curl_setopt($ch, CURLOPT_COOKIE, $cookie);
79 }
80 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
81 return curl_exec($ch);
82 }

2.4 修改域名访问配置

2.4.1 服务器端配置

[root@caogenba ~]# vim /etc/hosts
# 添加以下行,防止出现UC和应用出现通信失败的问题
192.168.10.135 www.caogen8.co mirror.caogen8.co www.cgzzn.com so.caogen8.co

2.4.2 客户端配置

将上面添加的行添加到C:\Windows\System32\drivers\etc\hosts文件中。

2.5 配置nginx

2.5.1 创建自签名证书

[root@caogenba ~]# cd /etc/ssl/
[root@caogenba ssl]# openssl genrsa -des3 -out server.key 1024
Enter pass phrase for server.key: 123456
Verifying - Enter pass phrase for server.key: 123456
[root@caogenba ssl]# openssl req -new -key server.key -out server.csr
Enter pass phrase for server.key: 123456
Country Name (2 letter code) [XX]:
State or Province Name (full name) []:
Locality Name (eg, city) [Default City]:
Organization Name (eg, company) [Default Company Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server‘s hostname) []:
Email Address []:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
[root@caogenba ssl]# openssl rsa -in server.key -out server.key
Enter pass phrase for server.key: 123456
[root@caogenba ssl]# openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

2.5.2 编写nginx配置文件

[root@caogenba ~]# mkdir -p /usr/local/nginx/conf/extras/

# 草根吧配置文件
[root@caogenba ~]# vim /usr/local/nginx/conf/extras/caogen8.conf
# 必须使用https,否则无法加载css,js等文件
server {
    listen       80;
    server_name  www.caogen8.co;
    rewrite ^/(.*) https://$server_name$request_uri? permanent;
}

server {
    listen   443 ssl;
    server_name  www.caogen8.co;

    ssl             on;
    ssl_certificate      /etc/ssl/server.crt;
    ssl_certificate_key  /etc/ssl/server.key;
    ssl_session_cache    shared:SSL:1m;
    ssl_session_timeout  5m;
    ssl_prefer_server_ciphers  on;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5;

    location / {
        root   html/caogenba;
        index  index.php index.html index.htm;
    }

    # 此处代码为discuz后台开启伪静态后自动生成,需添加到此处,否则只可以访问首页,其他二级目录均为404
    # 若不想使用伪静态也可以登陆论坛后台取消伪静态的使用,但是论坛中很多数据链接均是伪静态后的链接,若不开启伪静态则无法访问论坛讨论中的链接
    rewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 last;
    rewrite ^([^\.]*)/caogen/discuz/([0-9]+)/([0-9]+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3 last;
    rewrite ^([^\.]*)/f-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last;
    rewrite ^([^\.]*)/t-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last;
    rewrite ^([^\.]*)/g-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last;
    rewrite ^([^\.]*)/u-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3 last;
    rewrite ^([^\.]*)/b-([0-9]+)-([0-9]+)\.html$ $1/home.php?mod=space&uid=$2&do=blog&id=$3 last;
    rewrite ^([^\.]*)/(fid|tid)-([0-9]+)\.html$ $1/index.php?action=$2&value=$3 last;
    rewrite ^([^\.]*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ $1/plugin.php?id=$2:$3 last;

    location ~* .*\.(php|php5)?$ {
        root html/caogenba;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi.conf;
        fastcgi_param HTTPS on;
    }
}

# 草根吧源码站配置
[root@caogenba ~]# vim /usr/local/nginx/conf/extras/cgzzn.conf
server {
    listen       80;
    server_name  www.cgzzn.com;
    rewrite ^/(.*) https://$server_name$request_uri? permanent;
}

server {
    listen   443 ssl;
    server_name  www.cgzzn.com;

    ssl             on;
    ssl_certificate      /etc/ssl/server.crt;
    ssl_certificate_key  /etc/ssl/server.key;
    ssl_session_cache    shared:SSL:1m;
    ssl_session_timeout  5m;
    ssl_prefer_server_ciphers  on;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5;

    location / {
        root   html/cgzzn;
        index  index.php index.html index.htm;
    }

    # 此处开启的是discuz的伪静态配置
    rewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 last;
    rewrite ^([^\.]*)/article-([0-9]+)-([0-9]+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3 last;
    rewrite ^([^\.]*)/forum-(\w+)-([0-9]+)\.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last;
    rewrite ^([^\.]*)/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3 last;
    rewrite ^([^\.]*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last;
    rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3 last;
    rewrite ^([^\.]*)/blog-([0-9]+)-([0-9]+)\.html$ $1/home.php?mod=space&uid=$2&do=blog&id=$3 last;
    rewrite ^([^\.]*)/(fid|tid)-([0-9]+)\.html$ $1/index.php?action=$2&value=$3 last;
    rewrite ^([^\.]*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ $1/plugin.php?id=$2:$3 last;

    # 此处开启的是伪静态插件配置
    rewrite ^([^\.]*)/topic-(.+)\.html$ $1/portal.php?mod=topic&topic=$2 last;
    rewrite ^([^\.]*)/article-([0-9]+)-([0-9]+)\.html$ $1/portal.php?mod=view&aid=$2&page=$3 last;
    if (!-e $request_filename) {
    	rewrite ^([^\.]*)/f/(\w+)/([0-9]+)$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3 last;
    }
    if (!-e $request_filename) {
    	rewrite ^([^\.]*)/f/(\w+)$ $1/forum.php?mod=forumdisplay&fid=$2 last;
    }
    if (!-e $request_filename) {
    	rewrite ^([^\.]*)/t([0-9]+)/([0-9]+)$ $1/forum.php?mod=viewthread&tid=$2&page=$3 last;
    }
    if (!-e $request_filename) {
    	rewrite ^([^\.]*)/t/([0-9]+)$ $1/forum.php?mod=viewthread&tid=$2 last;
    }
    if (!-e $request_filename) {
    	rewrite ^([^\.]*)/g/([0-9]+)$ $1/forum.php?gid=$2 last;
    }
    if (!-e $request_filename) {
    	rewrite ^([^\.]*)/f/(\w+)/t([0-9]+)$ $1/forum.php?mod=forumdisplay&fid=$2&filter=typeid&typeid=$3 last;
    }
    if (!-e $request_filename) {
    	rewrite ^([^\.]*)/f/(\w+)/t([0-9]+)/([0-9]+)$ $1/forum.php?mod=forumdisplay&fid=$2&filter=typeid&typeid=$3&page=$4 last;
    }
    if (!-e $request_filename) {
    	rewrite ^([^\.]*)/f/(\w+)/s([0-9]+)$ $1/forum.php?mod=forumdisplay&fid=$2&filter=sortid&sortid=$3 last;
    }
    if (!-e $request_filename) {
    	rewrite ^([^\.]*)/f/(\w+)/s([0-9]+)/([0-9]+)$ $1/forum.php?mod=forumdisplay&fid=$2&filter=sortid&sortid=$3&page=$4 last;
    }
    if (!-e $request_filename) {
    	rewrite ^([^\.]*)/f/(\w+)/t([0-9]+)/s([0-9]+)$ $1/forum.php?mod=forumdisplay&fid=$2&filter=sortid&sortid=$4&typeid=$3 last;
    }
    if (!-e $request_filename) {
    	rewrite ^([^\.]*)/f/(\w+)/t([0-9]+)/s([0-9]+)/([0-9]+)$ $1/forum.php?mod=forumdisplay&fid=$2&filter=sortid&sortid=$4&typeid=$3&page=$4 last;
    }
    rewrite ^([^\.]*)/group-([0-9]+)-([0-9]+)\.html$ $1/forum.php?mod=group&fid=$2&page=$3 last;
    rewrite ^([^\.]*)/space-(username|uid)-(.+)\.html$ $1/home.php?mod=space&$2=$3 last;
    rewrite ^([^\.]*)/blog-([0-9]+)-([0-9]+)\.html$ $1/home.php?mod=space&uid=$2&do=blog&id=$3 last;
    rewrite ^([^\.]*)/(fid|tid)-([0-9]+)\.html$ $1/index.php?action=$2&value=$3 last;
    if (!-e $request_filename) {
    	rewrite ^([^\.]*)/tag/(thread|blog)/([0-9]+)/([0-9]+)$ $1/misc.php?mod=tag&id=$3&type=$2&page=$4 last;
    }
    if (!-e $request_filename) {
    	rewrite ^([^\.]*)/tag/([0-9]+)$ $1/misc.php?mod=tag&id=$2 last;
    }
    if (!-e $request_filename) {
    	rewrite ^([^\.]*)/tag$ $1/misc.php?mod=tag last;
    }
    rewrite ^([^\.]*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ $1/plugin.php?id=$2:$3 last;

    location ~* .*\.(php|php5)?$ {
        root html/cgzzn;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi.conf;
        fastcgi_param HTTPS on;
    }
}

# nginx主配置文件
[root@caogenba ~]# vim /usr/local/nginx/conf/nginx.conf
worker_processes  4;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    include extras/caogen8.conf;
    include extras/cgzzn.conf;
    include extras/xn.conf;
    include extras/banv.conf;
    include extras/o2o.conf;
}

2.5.3 重启nginx

[root@caogenba ~]# nginx -s reload

2.6 访问站点情况

Tips:若站点出现不完整或其他问题导致无法访问,可以从以下方面进行检查:

  1. 杀毒软件拦截
  2. 防广告插件拦截
  3. 浏览器对https中嵌套http页面进行安全拦截
  4. 可以更换其他浏览器进行测试(包括Firefox,IE,chrome等)

2.6.1 草根吧论坛

2.6.1.1 访问UC后台

  • 登陆UC后台:

图片[5]|草根吧论坛部署恢复|leon的博客

  • 修改管理员用户信息:

图片[6]|草根吧论坛部署恢复|leon的博客 图片[7]|草根吧论坛部署恢复|leon的博客

2.6.1.2 访问站点首页

图片[8]|草根吧论坛部署恢复|leon的博客

2.6.1.3 访问论坛管理后台

  • 登陆管理后台:

图片[9]|草根吧论坛部署恢复|leon的博客

图片[10]|草根吧论坛部署恢复|leon的博客

  • 配置网站伪静态:

图片[11]|草根吧论坛部署恢复|leon的博客 图片[12]|草根吧论坛部署恢复|leon的博客

2.6.2 草根吧源码站

2.6.2.1 访问UC后台

图片[13]|草根吧论坛部署恢复|leon的博客 图片[14]|草根吧论坛部署恢复|leon的博客

图片[15]|草根吧论坛部署恢复|leon的博客

2.6.2.2 访问站点首页

图片[16]|草根吧论坛部署恢复|leon的博客

2.6.2.3 访问源码站管理后台

  • 登陆管理后台:

图片[17]|草根吧论坛部署恢复|leon的博客

  • 配置discuz默认伪静态规则:

图片[18]|草根吧论坛部署恢复|leon的博客

  • 配置插件伪静态规则:

图片[19]|草根吧论坛部署恢复|leon的博客 图片[20]|草根吧论坛部署恢复|leon的博客

第3章 存在的问题

1、论坛无法搜索

2、论坛帖子中的图片无法显示(源程序从cdn.caogen8.co获取图片,貌似站点整包中没有相关的图片存档)

温馨提示:本文最后更新于2022-12-20 20:57:44,已超过431天没有更新。某些文章具有时效性,若文章内容或图片资源有错误或已失效,请联系站长。谢谢!
转载请注明本文链接:https://blog.leonshadow.cn/763482/1366.html
© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享