Discuz! X3.3站点部署SSL后兼容HTTPS访问教程

1、修改source/class/discuz/discuz_application.php(第187行)

$_G['isHTTPS'] = ($_SERVER['HTTPS'] && strtolower($_SERVER['HTTPS']) != 'off') ? true : false;

修改为:

$_G['isHTTPS'] = true;

2、修改uc_server/avatar.php(就在头几行)

define('UC_API', strtolower(($_SERVER['HTTPS'] == 'on' ? 'https' : 'http').'://'.$_SERVER['HTTP_HOST'].substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'))));

修改为:

define('UC_API', strtolower(($_SERVER['SERVER_PORT'] == 443 || $_SERVER['HTTPS'] == 'on' ? 'https' : 'http').'://'.$_SERVER['HTTP_HOST'].substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'))));

3、修改/template/default/common/header.htm
将http://全部查找替换为:https://(一共5处)

4、后台 – 全局 – 站点信息 – 网站 URL:将http://改成https://网址

5、后台 – 站长 – UCenter设置 – UCenter 访问地址改成https://网址

6、后台 – UCenter(如果不能正常访问可以在新窗口打开,也可以直接访问UC地址) – 应用管理 – 点右边的编辑 – 应用的主URL改成https://网址

7、后台 – 工具 – 更新缓存

8、后台 – 界面 – 风格,点击“更新CSS缓存”按钮

Photo.scr病毒是怎么被上传的?Photo.scr病毒怎么清除和防范?

有段时间笔者的win2003服务器上出现大量Photo.scr病毒,庆幸的是检查任务管理器后并没有发现可疑进程,说明病毒没有被执行。

删除后没清静多少时间,这些病毒又冒出来了。

这些Photo.scr的路径都在IIS自带FTP的路径下,关闭FTP服务就不再出现了,只要一开FTP过段时间又会出现。

然后就认为黑客是利用了IIS自带的FTP漏洞上传的病毒文件,只要不用FTP时就关掉FTP服务。

刚刚发现原来是开了FTP的匿名连接导致的,只要取消“允许匿名连接”的勾就解决了。
%title插图%num

这段时间笔者在给网站搬家时,发现Defender对网站文件进行报毒,查看后是被加入了以下恶意代码,以达到病毒传播的目的。
<iframe src=Photo.scr width=1 height=1 frameborder=0></iframe>
%title插图%num

黑客并没有批量添加代码,只改了2个文件,而且不仅限是html文件,还有xml文件也没幸免,应该是黑客觉得批量添加容易被发现,所以手动添加。

清除Photo.scr病毒:
1、如果没有运行它,直接搜索Photo.scr并删除就可以了,如果已经运行过,建议杀毒或重装系统。
2、检查下文件有没有被添加恶意代码,虽然已经删除Photo.scr不会再传播,但是安全软件还是会报毒提示,如果被添加恶意代码删除即可。

安全防范建议:
1、虽然知道了是开了FTP的匿名连接导致病毒上传,不过还是建议不用FTP的时候还是关闭它,谁知道它还会有其它的什么漏洞呢。
2、建议FTP的目录不要直接设在网站目录,如需上传文件到网站目录,可以先上传到别处再通过复制或剪切到网站目录。
3、更改FTP默认端口,避免被黑客的端口扫描器扫到。

Discuz! X3.2本地附件全部修改为远程附件的方法

进行操作前,请备份数据库

一、本地转到远程

1、论坛后台–全局–上传设置–启用远程附件

2、将本地附件目录data/attachment里面的文件夹移动到远程服务器上

3、数据库执行sql语句

论坛的(0表示本地,1表示远程,)

update pre_forum_attachment_0 set remote=1 where remote=0;
update pre_forum_attachment_1 set remote=1 where remote=0;
update pre_forum_attachment_2 set remote=1 where remote=0;
update pre_forum_attachment_3 set remote=1 where remote=0;
update pre_forum_attachment_4 set remote=1 where remote=0;
update pre_forum_attachment_5 set remote=1 where remote=0;
update pre_forum_attachment_6 set remote=1 where remote=0;
update pre_forum_attachment_7 set remote=1 where remote=0;
update pre_forum_attachment_8 set remote=1 where remote=0;
update pre_forum_attachment_9 set remote=1 where remote=0;

门户的

update pre_portal_article_title set remote=1 where remote=0;
update pre_portal_attachment set remote=1 where remote=0;
update pre_portal_topic_pic set remote=1 where remote=0;

相册的{相册表中的remote取值还有一种情况为remote=2(论坛附件图片保存到相册)}

update pre_home_pic set remote=remote+1;

二、远程转到本地
后台关闭远程附件设置,将附件移动到本地服务器的 data/attachment目录后执行sql即可
0表示本地,1表示远程

update pre_forum_attachment_0 set remote=0 where remote=1;
update pre_forum_attachment_1 set remote=0 where remote=1;
update pre_forum_attachment_2 set remote=0 where remote=1;
update pre_forum_attachment_3 set remote=0 where remote=1;
update pre_forum_attachment_4 set remote=0 where remote=1;
update pre_forum_attachment_5 set remote=0 where remote=1;
update pre_forum_attachment_6 set remote=0 where remote=1;
update pre_forum_attachment_7 set remote=0 where remote=1;
update pre_forum_attachment_8 set remote=0 where remote=1;
update pre_forum_attachment_9 set remote=0 where remote=1;
update pre_portal_article_title set remote=0 where remote=1;
update pre_portal_attachment set remote=0 where remote=1;
update pre_portal_topic_pic set remote=0 where remote=1;
update pre_home_pic set remote=remote-1;

修改Discuz! X3.2登录框提示文字“UID/用户名/Email”教程

移动互联网时代,越来越多的网站支持手机号登录,Discuz!程序也有相关的插件做了支持,但由于登录框提示文字不在在嵌入点,因此插件无法进行修改,需要站长手动进行修改。
以下是修改方法:

第一步:
打开source\language\member\lang_template.php
增加

'mobilenumber' => '手机号',

第二步:修改template\default\member\login_simple.htm
在25行

{lang username}

后面加入

/{lang mobilenumber}

第三步:更新缓存即可。

效果如下:
%title插图%num

Windows命令行生成keystore方法

生成keystore需要安装环境
可从Oracle官方下载:https://www.oracle.com/technetwork/java/javase/downloads/index.html

运行CMD打开命令提示符(WIN10环境用管理员运行,否则没有生成文件的权限)

如果没有配置过系统环境变量,需要添加临时环境变量

set PATH=%PATH%;"C:\Program Files (x86)\Java\jdk1.8.0_101\bin"

进入JDK的bin目录:CD C:\Program Files (x86)\Java\jdk1.8.0_101\bin

运行如下命令:

keytool -genkey -alias jiangdefu -keyalg RSA -validity 20000 -keystore jiangdefu.keystore

(-validity 20000代表有效期天数),命令完成后,bin目录中会生成jiangdefu.keystore

查看命令

keytool -list -keystore "jiangdefu.keystore"

输入你设置的keystore密码,可以查看证书指纹。

Discuz! X3.2开启https后UCenter通信失败的解决方法

打开uc_server\model\misc.php第68行找到

$port = !empty($matches['port']) ? $matches['port'] : 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);
}

通信成功!

Linux下安装OpenSSL

在为apache站点部署SSL证书时,根据阿里云的安装说明做到下面这步:

打开 apache 安装目录下 conf 目录中的 httpd.conf 文件,找到以下内容并去掉“#”:

#LoadModule ssl_module modules/mod_ssl.so (如果找不到请确认是否编译过 openssl 插件)
#Include conf/extra/httpd-ssl.conf

打开httpd.conf后发现还真找不到#LoadModule ssl_module modules/mod_ssl.so
找了下原因,应该是编译apache的时候没弄好,那么就重新安装OpenSSL一下

1、wget http://www.openssl.org/source/openssl-1.0.0e.tar.gz

2、解压缩,命令:tar -xzf openssl-1.0.0e.tar.gz,得到openssl-openssl-1.0.0e文件夹

3、进入解压的目录:cd openssl-1.0.0e

4、设定Openssl 安装,( –prefix )参数为欲安装之目录,也就是安装后的档案会出现在该目录下:
执行命令: ./config –prefix=/usr/local/openssl

5、执行命令./config -t

6.执行make,编译Openssl

7、安装 Openssl:
make install

8、执行以下命令
cd /usr/local
ldd /usr/local/openssl/bin/openssl
出现如下类似信息后检查安装情况。
%title插图%num

9、查看路径 which openssl

10、查看版本 openssl version

 

参考:http://blog.csdn.net/dazhi_100/article/details/17143213

不用写正则,一段代码即可实现HTTP到HTTPS的跳转

整个互联网环境越来越重视信息安全,越来越多的站长已经部署SSL证书或正在部署。

部署HTTPS后,访客仍然会访问HTTP的网页,但如果直接将HTTP 全局301 到HTTPS往往会出现一些兼容性的问题,比如有些程序的插件不支持HTTPS,或部分网站接口必须依赖HTTP。最主要还有很多站长不懂301跳转的正则代码,那么可使用以下代码,轻松实现跳转。

<script type="text/javascript">
var url = window.location.href;
              if (url.indexOf("https") < 0) {
                  url = url.replace("http:", "https:");
                  window.location.replace(url);
              }
</script>

更新:
该方法用于DiscuzX 程序时会造成页面错乱的问题
造成该问题的原因是由于访客访问HTTP页面时程序获取的仍然是HTTP地址,并将该地址写入缓存文件中。如以下代码

<base href="http://www.Example.com/" />

该代码的作用是给页面上所有相对 URL 规定基准 URL,通过本文方法跳转到HTTPS后并不会重新生成缓存,仍然访问了HTTP的基准URL,从而造成页面错乱的问题。

因此DiscuzX 程序必须通过301跳转到HTTPS才能正常访问。

IIS6支持.htaccess伪静态文件的设置方法

一度以为IIS6设置伪静态的方法只有添加Rewrite组件到Isapi筛选器,然后在httpd.ini设置伪静态规则。
用此方法设置的规则将应用到IIS上的所有站点,容易造成规则冲突。
有些网站程序只提供了.htaccess伪静态文件,也就用不了该方法。

在以下是IIS6支持.htaccess伪静态文件的设置方法。

首先下载ISAPI_Rewrite3 full完整版 静态化组件
下载链接:http://www.jb51.net/softs/66905.html#download

根据提示安装完后重启IIS即可生效。