nginx + php8.2 的方式来搭建discuz站点
discuz在php中的配置和运行
修改 php.ini,去掉下面的注释(即:去掉前面的分号)
- extension_dir = “D:/dev/php-8.2.27-nts/ext”
- extension=gd
- extension=mbstring
- extension=mysqli
运行php-cgi命令来启动php:
1cd D:\dev\php-8.2.27-nts
2php-cgi.exe -b 127.0.0.1:9000
discuz在nginx的配置和运行
nginx的配置方式有两种
方案一:discuz在nginx中作为单独的server
这种方式的配置非常简单,discuz直接可以用server_name的域名访问;示例如下:
1 server {
2 listen 80;
3 server_name bbs.zcily.com;
4
5 location / {
6 root D:/dev/workspaces/bbs-discuz;
7 index index.php index.html index.htm;
8 }
9
10 location ~ \.php$ {
11 root D:/dev/workspaces/bbs-discuz;
12 fastcgi_pass 127.0.0.1:9000;
13 fastcgi_index index.php;
14 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
15 include fastcgi_params;
16 }
17 }
启动nginx后,直接在浏览器中访问:http://bbs.zcily.com 即可
方案二:discuz在nginx中作为一个的server的子路径
这种方式,经过本人尝试,有很多错误;如:
- 上传图片后无法正常展示
配置示例如下:
1 server {
2 listen 80;
3 server_name zcily.com;
4
5 #其他配置省略......
6
7 location ~ ^/bbs/.+\.php$ {
8 root D:/dev/workspaces/DiscuzX;
9 fastcgi_pass 127.0.0.1:9000;
10 fastcgi_index index.php;
11 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
12 include fastcgi_params;
13 }
14
15 # 这个正则一定要放后面,否则php文件将不会被解析
16 location ~ ^/bbs/ {
17 root D:/dev/workspaces/DiscuzX;
18 index index.php index.html index.htm;
19 }
20
21 #其他配置省略......
22 }
注意:
- discuz的源码必须放在root路径中的子路径中;以上面为例,源码的根目录为
D:/dev/workspaces/DiscuzX/bbs - 读取非php文件(如js、css、图片等)的location块必须放在解析php的location块之后,否则也会出现静态文件不能被解析的问题
启动nginx后,在浏览器中访问地址:http://zcily.com/bbs/
discuz markdown 插件的安装
下载地址:https://github.com/panjianning/dz_markdown
注意:该插件只在php8.2中测试通过,其他php版本不能保证能正常运行。
评论