rewrite项目实例----搭建discuz网站

Posted givenchy_yzl

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了rewrite项目实例----搭建discuz网站相关的知识,希望对你有一定的参考价值。

项目需求

部署discuz,并实现伪静态
实现https
实现实时备份

一、实验准备

1.在discuz官网上下载到discuz压缩包并上传到web01中的/www/discuz目录下并解压
2.backup机器已经配置完成
3.nfs挂载点创建完成

二、mysql

#登录数据库
[root@db01 ~]# mysql -uroot -p123
#创建数据库
MariaDB [(none)]> create database discuz;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]>  grant all on discuz.* to yzl@'%' identified by '123';
Query OK, 0 rows affected (0.08 sec)

三、web服务器

#编辑discuz网页配置文件
[root@web01 conf.d]# vim discuz.conf
server{
    listen 80;
    server_name linux.discuz.com;
    location / {
        root /www/discuz/upload;
        index index.php index.html;
    }
    include php.params;
}

#编辑PHP配置文件
[root@web01 conf.d]# vim php.params
location ~ \\.php$ {
    root /www/discuz/uplod;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

#创建站点目录部署代码
[root@web01 conf.d]# mkdir /www/discuz
[root@web01 conf.d]# cd /www/discuz/
[root@web01 discuz]# rz -E
rz waiting to receive.
[root@web01 discuz]# unzip Discuz_X3.4_SC_UTF8_20210320.zip 

#测试并重启
[root@web01 www]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@web01 www]# systemctl restart nginx

#在本地hosts中添加
192.168.1.7   linux.discuz.com

#在浏览器访问、并安装

#随便发表一篇帖子,获取到帖子的url地址如下:
http://linux.discuz.com/forum.php?mod=viewthread&tid=1&extra=

#为网站设置伪静态
[root@web01 www]# vim /etc/nginx/conf.d/discuz.conf 
server {
    listen 80;
    server_name linux.discuz.com;

    location / {
        root /www/discuz/upload;
        index index.php;
        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/archiver/index.php?action=$2&value=$3 last;
        rewrite ^([^\\.]*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\\-]+)\\.html$ $1/plugin.php?id=$2:$3 last;
        if (!-e $request_filename) {
            return 404;
        }

    }
    include php.params;
}

[root@web01 conf.d]# systemctl restart nginx

#对比网址
伪静态前帖子网址:http://linux.discuz.com/forum.php?mod=viewthread&tid=1&extra=
伪静态后帖子网址http://linux.discuz.com/thread-1-1-1.html

#实现https


#检查nginx能否使用证书
[root@web01 ~]# nginx -V
--with-http_ssl_module
#必须有上面这个模块才可以使用证书

#创建证书存放目录
[root@web01 ~]# mkdir /etc/nginx/ssl_key
[root@web01 ~]# cd /etc/nginx/ssl_key/

#生成证书
[root@web01 ssl_key]#  openssl genrsa -idea -out server.key 2048
Generating RSA private key, 2048 bit long modulus
.......................................................................+++
.+++
e is 65537 (0x10001)
Enter pass phrase for server.key:123456  # 密码4-1023位即可
Verifying - Enter pass phrase for server.key:123456  #确认密码

[root@web01 ssl_key]# openssl req -days 36500 -x509 -sha256 -nodes -newk
ey rsa:2048 -keyout server.key -out server.crt
Generating a 2048 bit RSA private key
........................................................+++
...........................................+++
writing new private key to 'server.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:zg
State or Province Name (full name) []:riben
Locality Name (eg, city) [Default City]:pari
Organization Name (eg, company) [Default Company Ltd]:oldboy
Organizational Unit Name (eg, section) []:oldboy
Common Name (eg, your name or your server's hostname) []:discuz
Email Address []:123@qq.com

#命令注解
openssl req -days 36500 -x509 -sha256 -nodes -newkey rsa:2048 -keyout server.key -out server.crt
# req  --> 用于创建新的证书
# new  --> 表示创建的是新证书    
# x509 --> 表示定义证书的格式为标准格式
# key  --> 表示调用的私钥文件信息
# out  --> 表示输出证书文件信息
# days --> 表示证书的有效期

[root@web01 ssl_key]# ll
total 8
-rw-r--r-- 1 root root 1375 May  8 11:12 server.crt
-rw-r--r-- 1 root root 1704 May  8 11:12 server.key

#配置nginx证书
[root@web01 ssl_key]# vim /etc/nginx/conf.d/discuz.conf
server {
    listen 443 ssl;
    server_name linux.discuz.com;
    ssl_certificate /etc/nginx/ssl_key/server.crt;
    ssl_certificate_key /etc/nginx/ssl_key/server.key;
    #rewrite ^(.*)$ https://$server_name$1;
    location / {
        root /www/discuz/upload;
        index index.php;
        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/archiver/index.php?action=$2&value=$3 last;
        rewrite ^([^\\.]*)/([a-z]+[a-z0-9_]*)-([a-z0-9_\\-]+)\\.html$ $1/plugin.php?id=$2:$3 last;
        if (!-e $request_filename) {
            return 404;
        }

    }
    include php.params;
}

#重启nginx
[root@web01 ssl_key]# systemctl restart nginx

#浏览器输入:https://linux.discuz.com
#注:此时已完成https访问,但没有完成输入HTTP跳转到https

#在nfs+backup准备好后挂载即可

四、backup+nfs

backup
#开启rsyncd服务
[root@web01 ~]#systemctl restart rsyncd



nfs上
[root@nfs ~]# systemctl restart nfs
[root@nfs ~]# cd /usr/local/sersync2/
#更改conf.xml文件#开启实时同步服务
[root@pingnfs sersync2]# ./sersync2 -dro ./confxml.xml

以上是关于rewrite项目实例----搭建discuz网站的主要内容,如果未能解决你的问题,请参考以下文章

图文详解阿里云下lamp+discuz搭建实例

Apache下使用rewrite实现discuz伪静态的配置

LAMP+discuz网站搭建过程

LAMP 之四 Discuz 论坛搭建(实例)

centos7.4安装最新lnmp架构设置授权访问并搭建Discuz论坛

阿里云centos7.6服务器搭建discuz论坛详细步骤