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

本文档详细介绍了如何部署Discuz论坛,实现伪静态URL,配置HTTPS安全连接,以及设置实时备份。首先,在web服务器上安装并配置Discuz,创建数据库并授权,然后编辑Nginx配置文件实现伪静态。接着,生成SSL证书以启用HTTPS。最后,讨论了实时备份的设置,包括rsync服务的启动和NFS的挂载。整个过程详细且步骤清晰。
摘要由CSDN通过智能技术生成

项目需求

部署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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值