HDwiki+discuz在启用https下的整合问题
这几天在折腾HDwiki+discuz,系统环境是FreeBSD 10.4, PHP 5.6(HDwiki要求),PHP-PDO_MYSQL,PHP-GD,PHP-XML等,MYSQL 5.7
HDwiki 5.1(6.0安装成功后打开前台,提示http 500错误,找不到原因)
discuz X3.4
因为宽带运营商关闭了80端口,443端口有开,所以就直接用上https,结果问题一大堆。
首先,discuz和ucenter在https下通信失败,后来找到修改方法:
DISCUZ 开启https后ucenter通信失败解决方法,一般是做完301重定向https后通信失败的,下面是具体解决方法:
打开目录 uc_server/model/misc.php 文件;找到69行,插入下面代码:
...... $port = !empty($matches['port']) ? $matches['port'] : ($matches['scheme'] == 'https' ? 443 : 80); //以下为插入代码 if(substr($url,0,5)=='https'){ $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); if($post){ curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); } if($cookie){ curl_setopt($ch, CURLOPT_COOKIE, $cookie); } curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); return curl_exec($ch); } //插入代码结束 if($post) { $out = "POST $path HTTP/1.0\r\n"; ......
接下来设置HDwiki和ucenter,问题比较多了。
一开始,只要设置https,就提示“您输入的URL地址不正确!”
网上也没有任何资料,经过调试,发现要修改HDwiki目录下的control/admin_setting.php的659行
原来长这样:
if(empty($ucapi) || !preg_match("/^(http:\/\/)/i", $ucapi)) {
修改成这样:
if(empty($ucapi) || !preg_match("/^((http:|https:)\/\/)/i", $ucapi)) {
这个问题解决后,出现的是“uc_url_unreachable”错误。走了不少弯路后,发现还是https的问题。
admin_setting.php调用了api/uc_client/client.php里的uc_fopen(),而这个函数使用fsockopen模拟浏览器进行访问。
并且只有拼接了http协议的情况。对这个接口文件的分析,见这篇文章http://blog.csdn.net/yanhui_wei/article/details/17919645
综合这些分析,比较一下discuz的uc_server/model/misc.php和HDwiki下的api/uc_client/client.php,会发现:
discuz的uc_server/model/misc.php里的function dfopen2()和 function dfopen()与HDwiki下的api/uc_client/client.php的uc_fopen2()和uc_fopen()基本上是类似的。
所以解决方法如下:
1、拷贝discuz下的uc_client目录,替换HDwiki下的api/uc_client目录
2、修改api/uc_client/client.php文件,重点在于用function dfopen2()和 function dfopen()的内容替换uc_fopen2()和uc_fopen(),修改完成的结果如下:
function uc_fopen2($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE, $encodetype = 'URLENCODE') { $__times__ = isset($_GET['__times__']) ? intval($_GET['__times__']) + 1 : 1; if($__times__ > 2) { return ''; } $url .= (strpos($url, '?') === FALSE ? '?' : '&')."__times__=$__times__"; return uc_fopen($url, $limit, $post, $cookie, $bysocket, $ip, $timeout, $block, $encodetype); } function uc_fopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE , $ip = '', $timeout = 15, $block = TRUE, $encodetype = 'URLENCODE') { $return = ''; $matches = parse_url($url); $scheme = $matches['scheme']; $host = $matches['host']; $path = $matches['path'] ? $matches['path'].($matches['query'] ? '?'.$matches['query'] : '') : '/'; $port = !empty($matches['port']) ? $matches['port'] : ($matches['scheme'] == 'https' ? 443 : 80); /* //以下内容可以不需要 if($scheme=='https'){ $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); if($post) { curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $post); } if($cookie) { curl_setopt($curl, CURLOPT_COOKIE, $cookie); } curl_setopt($curl, CURLOPT_TIMEOUT, $timeout); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $return = curl_exec($curl); if (curl_errno($curl)) { echo '<pre><b>错误:</b><br />'.curl_error($curl); } curl_close($curl); return $return; } // 结束 */ if($post) { $out = "POST $path HTTP/1.0\r\n"; $header = "Accept: */*\r\n"; $header .= "Accept-Language: zh-cn\r\n"; $boundary = $encodetype == 'URLENCODE' ? '' : ';'.substr($post, 0, trim(strpos($post, "\n"))); $header .= $encodetype == 'URLENCODE' ? "Content-Type: application/x-www-form-urlencoded\r\n" : "Content-Type: multipart/form-data$boundary\r\n"; $header .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n"; $header .= "Host: $host:$port\r\n"; $header .= 'Content-Length: '.strlen($post)."\r\n"; $header .= "Connection: Close\r\n"; $header .= "Cache-Control: no-cache\r\n"; $header .= "Cookie: $cookie\r\n\r\n"; $out .= $header.$post; } else { $out = "GET $path HTTP/1.0\r\n"; $header = "Accept: */*\r\n"; $header .= "Accept-Language: zh-cn\r\n"; $header .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n"; $header .= "Host: $host:$port\r\n"; $header .= "Connection: Close\r\n"; $header .= "Cookie: $cookie\r\n\r\n"; $out .= $header; } $fpflag = 0; if(!$fp = @fsocketopen(($scheme == 'https' ? 'ssl' : $scheme).'://'.($scheme == 'https' ? $host : ($ip ? $ip : $host)), $port, $errno, $errstr, $timeout)) { $context = array( 'http' => array( 'method' => $post ? 'POST' : 'GET', 'header' => $header, 'content' => $post, 'timeout' => $timeout, ), ); $context = stream_context_create($context); $fp = @fopen($scheme.'://'.($scheme == 'https' ? $host : ($ip ? $ip : $host)).':'.$port.$path, 'b', false, $context); $fpflag = 1; } if(!$fp) { return ''; } else { stream_set_blocking($fp, $block); stream_set_timeout($fp, $timeout); @fwrite($fp, $out); $status = stream_get_meta_data($fp); if(!$status['timed_out']) { while (!feof($fp) && !$fpflag) { if(($header = @fgets($fp)) && ($header == "\r\n" || $header == "\n")) { break; } } $stop = false; while(!feof($fp) && !$stop) { $data = fread($fp, ($limit == 0 || $limit > 8192 ? 8192 : $limit)); $return .= $data; if($limit) { $limit -= strlen($data); $stop = $limit <= 0; } } } @fclose($fp); return $return; } } .... //找到同步登录登出代码,修改成以下内容 /** * 进入同步登录代码 * * @param int $uid 用户ID * @return string HTML代码 */ function uc_user_synlogin($uid) { $uid = intval($uid); $return = uc_api_post('user', 'synlogin', array('uid'=>$uid)); return $return; } /** * 进入同步登出代码 * * @return string HTML代码 */ function uc_user_synlogout() { $return = uc_api_post('user', 'synlogout', array()); return $return; } ....
然后就可以看到一切都正常了。
另外需要注意的是,必须保证ssl证书在有效期内,因为这个,浪费了2天的时间。
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
【好文】带你用Python开发个机器学习软件!
Python 开发windows GUI程序是比较简单的,并且相比于C++学习成本比较低,并且其效果也不错。常用的Python GUI框架有: Tkinter,Wxpython,Pygtk,Pyqt,Pyside,Kivy。在这里基于我个人推荐的话建议认真学习Pyqt和Kivy(我自己仅熟悉这两个),下面我们先简单的介绍一下这几个Python GUI框架,然后基于一个最简单的机器学习模型,实现一个基于GUI的机器学习应用。 1.Python GUI框架介绍 Tkinter: 是Python内嵌的GUI环境,使用TCL实现,其中Python IDLE 就是由Tkinter实现,其发展历史比较悠久,并且在Python的标准安装包中就包含了Tkinter,易学易用,跨平台,听说实现出的效果比较简陋(关键靠人) Wxpython:由C++编写,
- 下一篇
类似gitbook的wiki选择
一直以来,都使用xwiki作为团队内部的文档管理工具,但一直想换一个比较轻量级的系统。团队成员普遍对gitbook风格有好感,于是先后试用了mdwiki、dokuwiki、hexo、mindoc、wikitten。 mdwiki:纯粹用AJAX写的,部署最简单,但是目录只能两级; dokuwiki:PHP写的,没有数据库,有不少插件。一直在这个和wikitten中犹豫,最后还是选择了wikitten,主要还是界面风格,wikitten比较简洁; hexo:采用node.js开发的,也是因为这个才知道wikitten。因为服务器上已经有PHP的环境了,不想再增加node.js,所以放弃了,否则是很好的选择; mindoc:golang开发的,这个其实也不错,但我只要一本书,他却提供了一个书柜; wikitten:PHP写的,没有数据库,没有插件,文档也少。但界面一眼看中了,就这样了。 到github下载,解压。网上说PHP需要fileinfo组件,其实还需要json组件,这个需要注意了。由于我使用nginx,并且没法安装到站点根目录下,所以一直有问题。 location ~* ^/sta...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- SpringBoot2整合Thymeleaf,官方推荐html解决方案
- CentOS6,7,8上安装Nginx,支持https2.0的开启
- CentOS6,CentOS7官方镜像安装Oracle11G
- 设置Eclipse缩进为4个空格,增强代码规范
- CentOS7,8上快速安装Gitea,搭建Git服务器
- Jdk安装(Linux,MacOS,Windows),包含三大操作系统的最全安装
- CentOS7编译安装Cmake3.16.3,解决mysql等软件编译问题
- CentOS7,CentOS8安装Elasticsearch6.8.6
- Linux系统CentOS6、CentOS7手动修改IP地址
- SpringBoot2整合MyBatis,连接MySql数据库做增删改查操作