lnmp架构部署Discuz论坛并配置重定向转发
环境说明:
主机名 | 安装服务 | 系统版本 |
---|---|---|
lnmp | nginx-1.24.0 MySQL-8.0.33 php-8.2.9 | centos 8 |
部署Discuz论坛系统
# 下载Discuz论坛
[root@lnmp ~]# cd /usr/src
[root@lnmp src]# wget https://gitee.com/Discuz/DiscuzX/attach_files/1543382/download/Discuz_X3.5_SC_UTF8_20231001.zip
# 创建解压位置
[root@lnmp ~]# mkdir /usr/local/nginx/html/Discuz
[root@lnmp src]# unzip -d /usr/local/nginx/html/Discuz/ Discuz_X3.5_SC_UTF8_20231001.zip
[root@lnmp src]# cd /usr/local/nginx/html/Discuz/
[root@lnmp Discuz]# ll Discuz
total 124
-rw-r--r-- 1 root root 8181 Oct 1 23:02 LICENSE
-rw-r--r-- 1 root root 33294 Dec 21 2022 qqqun.png
drwxr-xr-x 2 root root 124 Oct 2 00:28 readme
-rw-r--r-- 1 root root 70226 Mar 16 2023 readme.html
drwxr-xr-x 12 root root 4096 Oct 2 00:28 upload
-rw-r--r-- 1 root root 140 Feb 12 2023 utility.html
#创建数据库
[root@lnmp ~]# mysql -uroot -p12345678 -e "create database Discuz;"
[root@lnmp ~]# mysql -uroot -p12345678 -e "create user 'Discuz'@'localhost' identified by '610000';"
[root@lnmp ~]# mysql -uroot -p12345678 -e "grant all privileges on Discuz.* to 'Discuz'@'localhost';"
[root@lnmp ~]# mysql -uroot -p12345678 -e "flush privileges;"
#修改所需文件的属主属组、权限
[root@lnmp Discuz]# cd /usr/local/nginx/html/Discuz/upload/
[root@lnmp upload]# chmod -R 777 config/
[root@lnmp upload]# chmod -R 777 data/
[root@lnmp upload]# chmod -R 777 uc_client/
[root@lnmp upload]# chmod -R 777 uc_server/
#编辑nginx的配置文件,创建一个虚拟主机,使其可以用域名访问
[root@lnmp ~]# vim /usr/local/nginx/conf/nginx.conf
worker_processes 4;
worker_rlimit_nofile 65535;
worker_cpu_affinity 0001 0010 0100 1000;
error_log /var/log/nginx/error.log;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
gzip on;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
server {
listen 80;
server_name www.dis.com;
charset utf8;
access_log logs/host.access.log main;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location / {
root html/Discuz/upload;
index index.php index.html index.htm;
# 重定向转发
#if ($host = 'www.dis.com'){
# rewrite ^/(.*)$ http://www.bbs.com/$1 permanent;
#}
}
location ~ \.php$ {
root html/Discuz/upload;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $Document_Root$fastcgi_script_name;
include fastcgi_params;
}
}
}
#重启nginx
[root@lnmp ~]# systemctl restart nginx
#配置Windows电脑hosts文件
C:\Windows\System32\drivers\etc\hosts
添加以下两句
192.168.226.128 www.dis.com
192.168.226.128 www.bbs.com
进入Discuz安装界面
访问192.168.226.128/install
直接访问站点结束
重定向转发
if ($host = 'www.dis.com'){
rewrite ^/(.*)$ http://www.bbs.com/$1 permanent;
}
现在公司旧域名www.dis.com有业务需求变更,需要使用新域名www.bbs.com代替,但是旧域名不能废除,需要跳转到新域名上,而且后面的参数保持不变。
测试用旧的域名访问
自动跳转到新域名,正常访问