Board logo

标题: Discuz!X3.3+OPcache+伪静态 [打印本页]

作者: admin    时间: 2020-6-24 19:12     标题: Discuz!X3.3+OPcache+伪静态

笺注:这是在 LNMP一键安装包(lamp_CentOS6.9) 的基础上进行。 OPcache的安装可参考:Discuz!X2.5+OPcache+伪静态 PHP配置文件中,关于OPcache的配置:(此时OPcache的缓存功能已启用) [root@localhost ~]# vi /usr/local/php/etc/php.ini ;opcache [Zend Opcache] zend_extension="opcache.so" opcache.memory_consumption=128 opcache.interned_strings_buffer=8 opcache.max_accelerated_files=4000 opcache.revalidate_freq=60 opcache.fast_shutdown=1 opcache.enable_cli=1 测试OPcache的缓存功能: 在没有DNS服务器解析域名的情况下,可以在文件/etc/hosts里绑定: [root@localhost ~]# tail -1 /etc/hosts 192.168.168.130 www.zhuohua.store bbs.zhuohua.store [root@localhost ~]# ab -n 1000 -c 100 http://bbs.zhuohua.store/forum.php This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking bbs.zhuohua.store (be patient) Completed 100 requests Completed 200 requests Completed 300 requests Completed 400 requests Completed 500 requests Completed 600 requests Completed 700 requests Completed 800 requests Completed 900 requests Completed 1000 requests Finished 1000 requests Server Software: Apache Server Hostname: bbs.zhuohua.store Server Port: 80 Document Path: /forum.php Document Length: 12936 bytes Concurrency Level: 100 Time taken for tests: 5.482 seconds Complete requests: 1000 Failed requests: 0 Write errors: 0 Total transferred: 13747000 bytes HTML transferred: 12936000 bytes Requests per second: 182.41 [#/sec] (mean) Time per request: 548.228 [ms] (mean) Time per request: 5.482 [ms] (mean, across all concurrent requests) Transfer rate: 2448.76 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 2 7.4 0 26 Processing: 17 517 103.1 535 698 Waiting: 9 513 102.4 529 698 Total: 36 520 97.5 535 698 Percentage of the requests served within a certain time (ms) 50% 535 66% 549 75% 560 80% 565 90% 581 95% 606 98% 629 99% 665 100% 698 (longest request) 笺注:可以看到OPcache的缓存功能启用后,每秒最大处理请求次数为182.41次,每个请求响应时间是5.482毫秒。 在PHP配置文件中关闭OPcache的缓存功能: [root@localhost ~]# vi /usr/local/php/etc/php.ini 加上: opcache.enable=0 图片1.png 图片2.png 再次测试: [root@localhost ~]# ab -n 1000 -c 100 http://bbs.zhuohua.store/forum.php This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking bbs.zhuohua.store (be patient) Completed 100 requests Completed 200 requests Completed 300 requests Completed 400 requests Completed 500 requests Completed 600 requests Completed 700 requests Completed 800 requests Completed 900 requests Completed 1000 requests Finished 1000 requests Server Software: Apache Server Hostname: bbs.zhuohua.store Server Port: 80 Document Path: /forum.php Document Length: 12936 bytes Concurrency Level: 100 Time taken for tests: 24.128 seconds Complete requests: 1000 Failed requests: 999 (Connect: 0, Receive: 0, Length: 999, Exceptions: 0) Write errors: 0 Total transferred: 12965786 bytes HTML transferred: 12253683 bytes Requests per second: 41.45 [#/sec] (mean) Time per request: 2412.824 [ms] (mean) Time per request: 24.128 [ms] (mean, across all concurrent requests) Transfer rate: 524.78 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 1 3.4 0 12 Processing: 46 2372 631.9 2416 3839 Waiting: 21 2308 609.5 2325 3698 Total: 46 2373 629.6 2416 3839 Percentage of the requests served within a certain time (ms) 50% 2416 66% 2632 75% 2765 80% 2859 90% 3063 95% 3199 98% 3368 99% 3482 100% 3839 (longest request) 笺注:可以看到OPcache的缓存功能没有启用时,每秒最大处理请求次数为41.45次,每个请求响应时间是24.128毫秒。 在PHP配置文件中再次启用OPcache的缓存功能: [root@localhost ~]# vi /usr/local/php/etc/php.ini 修改: opcache.enable=1 图片3.png 图片4.png 再次测试: [root@localhost ~]# ab -n 1000 -c 100 http://bbs.zhuohua.store/forum.php This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking bbs.zhuohua.store (be patient) Completed 100 requests Completed 200 requests Completed 300 requests Completed 400 requests Completed 500 requests Completed 600 requests Completed 700 requests Completed 800 requests Completed 900 requests Completed 1000 requests Finished 1000 requests Server Software: Apache Server Hostname: bbs.zhuohua.store Server Port: 80 Document Path: /forum.php Document Length: 12936 bytes Concurrency Level: 100 Time taken for tests: 5.428 seconds Complete requests: 1000 Failed requests: 0 Write errors: 0 Total transferred: 13748152 bytes HTML transferred: 12936000 bytes Requests per second: 184.23 [#/sec] (mean) Time per request: 542.812 [ms] (mean) Time per request: 5.428 [ms] (mean, across all concurrent requests) Transfer rate: 2473.40 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 1 2.5 0 9 Processing: 24 521 106.9 483 961 Waiting: 22 515 105.8 477 961 Total: 31 521 108.4 483 961 Percentage of the requests served within a certain time (ms) 50% 483 66% 515 75% 538 80% 559 90% 651 95% 762 98% 894 99% 935 100% 961 (longest request) 笺注:可以看到OPcache的缓存功能再次启用后,每秒最大处理请求次数为184.23次,每个请求响应时间是5.428毫秒。 ############# ############# Discuz!是采用PHP语言开发的,动态地址不利于蜘蛛抓取,开启伪静态有利于SEO优化。 其实Discuz!不开启伪静态,也是可以进行蜘蛛抓取的。 Discuz!X3.3开启伪静态: 管理中心》全局》SEO设置》URL静态化: 图片5.png 图片6.png 注释:全选。 图片7.png 提交后,点击右上角的 查看当前的Rewrite规则 图片8.png 复制这一段代码:(站点Discuz!使用的是Apache基于域名的虚拟主机,所以这里选择Apache Web Server(虚拟主机用户) 图片9.png 笺注:也有Nginx的Rewrite规则: 图片10.png 在Discuz!的站点目录下,创建伪静态规则文件:( .htaccess ) [root@localhost ~]# cd /www/bbs.zhuohua.store/ [root@localhost bbs.zhuohua.store]# vi .htaccess # 将 RewriteEngine 模式打开 RewriteEngine On # 修改以下语句中的 /discuz 为您的论坛目录地址,如果程序放在根目录中,请将 /discuz 修改为 / #RewriteBase /discuz RewriteBase / # Rewrite 系统规则请勿修改 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^topic-(.+)\.html$ portal.php?mod=topic&topic=$1&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^article-([0-9]+)-([0-9]+)\.html$ portal.php?mod=view&aid=$1&page=$2&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^forum-(\w+)-([0-9]+)\.html$ forum.php?mod=forumdisplay&fid=$1&page=$2&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ forum.php?mod=viewthread&tid=$1&extra=page\%3D$3&page=$2&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^group-([0-9]+)-([0-9]+)\.html$ forum.php?mod=group&fid=$1&page=$2&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^space-(username|uid)-(.+)\.html$ home.php?mod=space&$1=$2&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^blog-([0-9]+)-([0-9]+)\.html$ home.php?mod=space&uid=$1&do=blog&id=$2&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^(fid|tid)-([0-9]+)\.html$ archiver/index.php?action=$1&value=$2&%1 RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^([a-z]+[a-z0-9_]*)-([a-z0-9_\-]+)\.html$ plugin.php?id=$1:$2&%1 [root@localhost bbs.zhuohua.store]# ll .htaccess -rw-r--r-- 1 root root 1312 2月 26 20:32 .htaccess 保存后,重启一下Apache: [root@localhost ~]# service httpd restart restart apache... done 测试: 伪静态开启后,也不是说所有URL的表现形式都显示为静态页面: 图片11.png 图片12.png 板块、文章的URL的表现形式都显示为静态页面: 图片13.png 图片14.png 相关文章: UPUPW_Ap5.6_XCache/OPCache+ionCube Loader

图片附件: 图片1.png (2021-2-27 10:56, 69.46 KB) / 下载次数 159
http://blog.zhuohua.store/attachment.php?aid=15651&k=6a0f6b3cd6a07943abc27ac3db4bc06c&t=1714356934&sid=NTsqf5



图片附件: 图片2.png (2021-2-27 10:56, 85.69 KB) / 下载次数 128
http://blog.zhuohua.store/attachment.php?aid=15652&k=a8db264807edaa80f6852b0b8ca4d5d2&t=1714356934&sid=NTsqf5



图片附件: 图片3.png (2021-2-27 10:57, 68.95 KB) / 下载次数 124
http://blog.zhuohua.store/attachment.php?aid=15653&k=cd4137b700d3ab85f747da584de39773&t=1714356934&sid=NTsqf5



图片附件: 图片4.png (2021-2-27 10:57, 85.69 KB) / 下载次数 133
http://blog.zhuohua.store/attachment.php?aid=15654&k=63272b57d33e98baa529dd767c93bddc&t=1714356934&sid=NTsqf5



图片附件: 图片5.png (2021-2-27 10:59, 123.41 KB) / 下载次数 130
http://blog.zhuohua.store/attachment.php?aid=15655&k=549c777acb02e060664767d8ac43ed43&t=1714356934&sid=NTsqf5



图片附件: 图片6.png (2021-2-27 10:59, 49.76 KB) / 下载次数 142
http://blog.zhuohua.store/attachment.php?aid=15656&k=4d0031408a519813a2b97622895c0d3d&t=1714356934&sid=NTsqf5



图片附件: 图片7.png (2021-2-27 10:59, 11.55 KB) / 下载次数 131
http://blog.zhuohua.store/attachment.php?aid=15657&k=65ff4383c2a365c509d42d81777b80bd&t=1714356934&sid=NTsqf5



图片附件: 图片8.png (2021-2-27 11:00, 3.71 KB) / 下载次数 128
http://blog.zhuohua.store/attachment.php?aid=15658&k=0879bf863f5b7196bdc817152b43d701&t=1714356934&sid=NTsqf5



图片附件: 图片9.png (2021-2-27 11:00, 172.69 KB) / 下载次数 123
http://blog.zhuohua.store/attachment.php?aid=15659&k=c7f29dd02ba01c3b158f0db62ebfcb77&t=1714356934&sid=NTsqf5



图片附件: 图片10.png (2021-2-27 11:01, 99.6 KB) / 下载次数 123
http://blog.zhuohua.store/attachment.php?aid=15660&k=76caf859e3ed7bbfc9eff92146c191b2&t=1714356934&sid=NTsqf5



图片附件: 图片11.png (2021-2-27 11:01, 112.94 KB) / 下载次数 133
http://blog.zhuohua.store/attachment.php?aid=15661&k=3017d4bb99315bd91f084c06cb61c625&t=1714356934&sid=NTsqf5



图片附件: 图片12.png (2021-2-27 11:02, 45.49 KB) / 下载次数 138
http://blog.zhuohua.store/attachment.php?aid=15662&k=2601b6bb7ced81c52f7fb1fd1bfcf117&t=1714356934&sid=NTsqf5



图片附件: 图片13.png (2021-2-27 11:02, 55.59 KB) / 下载次数 140
http://blog.zhuohua.store/attachment.php?aid=15663&k=b47aeeef5995dbf61b71f9847e356fd3&t=1714356934&sid=NTsqf5



图片附件: 图片14.png (2021-2-27 11:02, 92.43 KB) / 下载次数 138
http://blog.zhuohua.store/attachment.php?aid=15664&k=8388ac301018fa6ac9677585e0a442e1&t=1714356934&sid=NTsqf5






欢迎光临 blog.zhuohua.store (http://blog.zhuohua.store/) Powered by Discuz! 7.2