开启左侧

Discuz! X3.2 实现全站 HTTPS 终极教程 [

[复制链接] 10
回复
26524
查看
打印 上一主题 下一主题
楼主
跳转到指定楼层
发表于 2017-4-5 17:36 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?注册

x
discuz X3.2在系统上是支持https的,不过需要手动修改几个地方。首先确保服务器端已开启https,且正确配置了SSL证书。
$ a, k# T& G1 p; ~! b0 i" O% h) V6 H# K
discuz X3.2开启支持https主要需要修改一下几个地方:
/ r7 b# A- t" _5 s1 `, |
; O/ V* ?0 U! O+ U1、查找修改文件discuz_application.php :
$ \6 t- q6 x( D! _# x; E$ R, wsource/class/discuz/discuz_application.php (约第 187 行处): 查找:! I' s. [/ r; ]: T; r& x
$_G['isHTTPS'] = ($_SERVER['HTTPS'] && strtolower($_SERVER['HTTPS']) != 'off') ? true : false;( U! `4 P5 x- G( v$ R

6 U( }* j( ^+ o- S) V
$ Y/ h+ A1 s  \4 ~修改为:$ J* T. ~' Z; x- i; `
$_G['isHTTPS'] = ($_SERVER['SERVER_PORT'] == 443 || $_SERVER['HTTPS'] && strtolower($_SERVER['HTTPS']) != 'off') ? true : false;
- D3 p0 J! B: d
+ g8 T; t8 n. U2 a: U0 ^' U4 U, ~
" x8 w7 H: D- g) l8 P' ?2、查找修改文件avatar.php :& M, G: [( q" Y' U3 |: R) L) q
uc_server/avatar.php (约第 13 行处)查找:) n! z. R( y: M8 B  z' n

) n. U/ f4 ~0 C4 V
) u0 P; M0 w3 J) t1 U
define('UC_API', strtolower(($_SERVER['HTTPS'] == 'on' ? 'https' : 'http').'://'.$_SERVER['HTTP_HOST'].substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'))));* n- ]3 h! y. b$ H$ R: w
) H) S( N7 T- Q+ h) B) j( B
! E8 R! F5 n6 B1 F

' W+ d1 X2 W% O
6 ]! E0 U6 u3 L& |+ ]0 T, J: R
/ E; e: w  ~* l- A2 R6 b
修改为:6 F. y; y4 Y3 @/ C2 e9 x4 _$ B0 I
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'], '/'))));
* b2 }3 q7 Q, D" J/ i* K# a7 P3 j  J; i8 E) c1 l+ k

; i/ c7 g' g% _4 Z  `3、除去非 HTTPS 内容避免提示”不安全内容“) h" V, Y* @+ K" L' j. H* ~
Source/plugin/manyou/Service/DiscuzTips.php ,最后的那段 JS 加载脚本删除就行。
  m$ V8 x. C8 q, B非楼主层如果有点评,那么点评者头像不是 HTTPS 开头,也需要修改一个文件来适配: template/default/forum/viewthread_node_body.htm (约 180 行),搜索 div class="psta vm">,将下面一行注释掉或者删除。% X8 ^7 V. D# K: A& I% O! @
打开浏览器,使用开发者工具或者查看源码逐一排查加载的非 HTTPS 资源并修改。
- n- P1 }7 X$ K8 o+ A) S

% V0 a& X3 o2 t: m4、后台设置的修改完善- m( l5 n8 j, U! Q4 k5 i6 i
在后台还有一些设置,可能会干扰 https 的使用。

2 D+ z0 [! ~, x. h5 {$ _, `8 Q! ~4 }6 f. s
后台 >全局 > 站点 URL ,改为 https 开头的

$ z- \6 o! R) A2 P' x  u
, W0 ?1 k) K& K% k, d) J/ r后台 > 站长 > UCenter 设置 > UCenter 访问地址,修改为 https 开头的
% S2 n& v. h( H' A1 W

, @- k3 s. Q% B  {8 ^  `% MUCenter 后台 > 应用管理 > 应用的主 URL ,修改为 https 开头。
' Z4 G: G. d0 ~8 X
修改后可能会显示通讯失败,如果 UC 和论坛程序安装在同一机器,此失败可无视,实测可以和 UC 正常通讯不影响(测试是否正常通讯程序的 Bug ),如果 UC 和论坛程序不在一台机器上,有可能不能通讯。 另外在 后台 > 全局 > 域名设置 中的一些设置也可能使 https 失效,如果更新缓存后论坛默认连接还是 HTTP ,请删除 后台 > 全局 > 域名设置 > 应用域名 > 默认 里面的默认域名(一般去 forum.php 尾巴这里会有内容,为了 HTTPS 请删除)。
. T% Q" w' [3 a  E" v. |6 K" W7 f) j5 l6 ?8 ]# z9 F
5、模板的调整
7 ~+ A/ G" |- G7 f4 g. |. U% j主要在模板的 foot.html 以及 header.html 等文件中,使用工具逐一排查模板文件中写死的 HTTP 链接,修改为 HTTPS 。
6 _$ v5 t  ?, y- j# F$ j
: h4 K4 D9 E8 |8 Z& [4 c

/ ]& R4 S  \! J4 n- _% a6、数据库的调整" H- L+ S, t2 s- T
在论坛这种交互社区中,经常回复发帖时会有出现主域名的链接,在没有 HTTPS 之前,链接都是 HTTP 开头,这个时候,我们需要修改数据库,运行下面的 mysql 命令更新数据库,将 HTTP 替换为 HTTPS :
( X7 d1 _2 y: @5 y( q* g* ]0 I进入 DZ 后台:站长 – 数据库 – 升级
2 U# h4 F0 o3 p* E- [
UPDATE pre_forum_post SET message=REPLACE(message,'http://你的网址','https://你的网址');
( Z# K: x: F' ~% f8 d
! y$ ?4 z" ?+ f, l; n0 D& Z! Q- N6 N8 C. s
% @$ L: k7 f; K* [0 i; k
需要注意的是,出于安全考虑, Discuz 后台默认情况下禁止 SQL 语句直接执行,只能使用常用 SQL 当中的内容,如果想自己随意书写 SQL 升级语句,需要将程序文件 config/config_global.php 当中的$_config[admincp][runquery] 设置修改为 1 。
) F- I# w# {5 k! z% K' F) H- @) W% I4 Y, ^8 F, x
7 h5 u: R" I5 H' {
到此,discuz X3.2已经开启支持https了 。2 ~4 y1 K1 f9 f# x

9 y% x" ^0 A4 X6 ^) r
1 j; Q* @4 n& W: `
当然,你还需要申请SSL证书、在服务器端部署SSL证书。
2 a) I& m; _# A% e! ~6 b! i- j/ N$ b6 o* u4 f1 |0 j! b7 N" c
, w4 F, z% l- g$ C5 b6 M! y
服务器端部署https的SSL证书可以看我的这个教程:2 G* ^  Z# Q7 m& n
7 O# z6 V2 q+ D* h4 l0 R" c0 m. p
& Z4 P& D/ l9 l+ k
http://www.aitiancheng.com/article-246.html

转载请保留当前帖子的链接:https://www.beimeilife.com/thread-46275-1-1.html 谢谢
沙发
发表于 2017-4-5 18:02 | 只看该作者


Discuz X3.* 全站开启 SSL / HTTPS 后需解决的问题

http://www.vdazhang.com/wenzhang-1587.html/2


一、全站资源 https 化。

1、UCenter地址、本地附件 URL 地址、风格图片地址需全部开启https访问,否则浏览器会出现类似“网站内存在不安全的资源”的警告。如果这部分链接全部是相对链接,则请忽略本项。

若“风格管理”中将“界面基础图片目录 {IMGDIR}”和“扩展图片目录 {STYLEIMGDIR}” 地址设置为 https 开头的绝对链接,需要修复一处BUG,否则会导致这部分风格图片无法显示。

打开 source/function/cache/cache_styles.php ,查找以下三项:

$cssdata = !preg_match('/^http:\/\//i', $data['styleimgdir'])8 w# o* z. q+ g" X
$cssdata = !preg_match('/^http:\/\//i', $data['imgdir'])" B: ^( }8 `; P, l! `3 u* o
$cssdata = !preg_match('/^http:\/\//i', $data['staticurl'])

将其中的 /^http:\/\//i 替换为 /^http/i ,保存覆盖。

注意:修改后,若将来要使用相对链接,需要确保目录不以 http 开头。

2、解决 DiscuzTips 造成的不安全资源提示。

打开 source/plugin/manyou/Service/DiscuzTips.php ,在 echo $jsCode; 前加 // 将其注释掉。

3、百度结构化插件暂不支持 https ,将造成浏览器提示存在不安全资源。暂停使用该插件。

4、使用浏览器的开发者工具逐一排查是否存在其他 http:// 资源(包括图片、JS、CSS的,A链接无影响)。

5、清理用户签名位中的 http:// 图片,清理帖子中存在的外链图片。


二、解决QQ互联登录问题。

截至2015年12月,Discuz的QQ互联仍不支持 https 站点,我们可以进行以下操作,将QQ互联链接调整为 http:// ,QQ互联登录跳转回 http:// 后再在站点内部301到 https:// 页面。

1、考虑到防止屏蔽等因素,建议启用一个独立域名,并在论坛所在服务器新建一个该域名的站点,站点目录中使用软链接链接论坛的以下目录:api config data source static 和以下文件:admin.php api.php connect.php ,即相当于对论坛做一个镜像但仅限于QQ互联相关文件。

2、打开 source/plugin/qqconnect/connect.class.php 文件,将 40-46 行中的:

$_G['siteurl'].'

替换为:

'http://上面创建的专用网址/

3、打开 connect.php 文件,在最前方加入:

if($_SERVER['HTTP_HOST'] != 'www.你的网址.com' || ($_SERVER['HTTP_HOST'] == 'www.你的网址.com' && $_SERVER['SERVER_PORT'] != '443')) {
header('HTTP/1.1 301 Moved Permanently');
header('Location: https://www.你的网址.com'.$_SERVER['REQUEST_URI']);
exit;
}

三、解决后台应用中心无法访问的问题

在第2步基础上,访问第2步中专用域名下的 admin.php 登录后台即可正常进入应用中心。

四、禁止在第2步专用域名下更新缓存(否则前台部分图标地址会使用该域名)。

打开 source/admincp/admincp_tools.php 文件,查找:

	showtips('tools_updatecache_tips');- D4 {6 B& G3 X) ]: M

; A* W8 U2 {; U: L  c	if($step == 1) {% k% ~) ^" v+ C6 g
		cpmsg("<input type=\"checkbox\" name=\"type[]\" value=\"data\" id=\"datacache\" class=\"checkbox\" checked /><label for=\"datacache\">".$lang[tools_updatecache_data]."</label><input type=\"checkbox\" name=\"type[]\" value=\"tpl\" id=\"tplcache\" class=\"checkbox\" checked /><label for=\"tplcache\">".$lang[tools_updatecache_tpl]."</label><input type=\"checkbox\" name=\"type[]\" value=\"blockclass\" id=\"blockclasscache\" class=\"checkbox\" /><label for=\"blockclasscache\">".$lang[tools_updatecache_blockclass].'</label>', 'action=tools&operation=updatecache&step=2', 'form', '', FALSE);

替换为:

	showtips('tools_updatecache_tips');7 w1 K5 A+ |* N1 _$ `2 D& W
	echo '<br>';
1 w0 l$ Q) r5 F5 @( p" z9 u1 D
2 e) Y$ e8 N7 \; v# E9 `	if($step == 1) {5 T4 C5 f' E  q) P6 j
		if($_G['siteurl'] == $_G['setting'][siteurl]) {4 M  v6 N, U) w% p4 c  r7 ~' U
			cpmsg("<input type=\"checkbox\" name=\"type[]\" value=\"data\" id=\"datacache\" class=\"checkbox\" checked /><label for=\"datacache\">".$lang[tools_updatecache_data]."</label><input type=\"checkbox\" name=\"type[]\" value=\"tpl\" id=\"tplcache\" class=\"checkbox\" checked /><label for=\"tplcache\">".$lang[tools_updatecache_tpl]."</label><input type=\"checkbox\" name=\"type[]\" value=\"blockclass\" id=\"blockclasscache\" class=\"checkbox\" /><label for=\"blockclasscache\">".$lang[tools_updatecache_blockclass].'</label>', 'action=tools&operation=updatecache&step=2', 'form', '', FALSE);: l( U* _+ M2 V0 a$ x
		} else {4 G' b0 F+ R; h' n
			cpmsg('请切换到主域名下更新缓存', '', 'succeed', '', FALSE);



五、http:// 跳转至 https://

打开 source/class/class_core.php 文件,在

set_exception_handler(array('core', 'handleException'));

后面加入:

if($_SERVER['SERVER_PORT'] != '443' && $_SERVER['PHP_SELF'] != '/api/uc.php') {
3 ?( D  ?7 T" B/ D$ X	if(!preg_match("/(Zidingyi|Bot|Crawl|Spider|slurp|sohu-search|lycos|robozilla)/i", $_SERVER['HTTP_USER_AGENT'])) {; \; J6 d" ~/ ^, s2 q( D; j) @
		header('HTTP/1.1 301 Moved Permanently');+ M% s4 E3 N2 d
		header('Location: https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);5 }2 P( C# i1 N- I( }6 R; ]; T4 w
		exit;6 R0 G' m  g8 |
	} elseif(preg_match("/(Baidu|Google)/i", $_SERVER['HTTP_USER_AGENT'])) {
0 N. U( U. y' c8 z$ x* Y		header('HTTP/1.1 403 Forbidden');
1 p, C8 L6 q6 e4 @* y. c		exit;
# t: Q- j" Y6 ]9 c" H	}+ \; [" ?, I& v
}

说明:当访问端口不为443(即https)时,如果不是搜索引擎则跳转到https页面,否则如果是百度或Google蜘蛛(这两个搜索引擎已支持收录https)则返回403禁止访问,避免重复收录 http 和 https 或优先收录了 http ,其它搜索引擎未定义,正常返回 http 页面(其它搜索引擎可能不支持收录 https ,因此开放 http 给他们)。

以上代码中“Zidingyi”可以任意修改,管理员使用以下UA可以不跳转到https,便于对http版进行调测:
Mozilla/5.0 (compatible; Zidingyi/2015; +http://www.xxx.com)


六、其它问题


解决 Discuz! X3.* “允许发表的域名列表”中的域名在非http协议下失效的问题

BUG描述: 在 后台/全局/注册与访问控制/访问控制/允许发表的域名列表 中添加域名后,该域名只在http协 … 继续阅读解决 Discuz! X3.* “允许发表的域名列表”中的域名在非http协议下失效的问题



Discuz! X3.* 开启SSL后手机版图片链接替换为https地址

应用场景:后台“本地附件 URL 地址”设置为绝对链接(第三方域名、http://)情况下,当论坛应用SSL后 … 继续阅读


解决启用HTTPS后IE6/7下频繁报告“含有不安全的内容”以及“证书名称不一致”的问题

首先检查页面中所有非https链接的附件(图片、JS、CSS等),全部替换为https链接。 完成这一步后,在 … 继续阅读




板凳
发表于 2017-4-6 11:55 | 只看该作者

How To Set Up Apache with a Free Signed SSL Certificate on a VPS

https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-with-a-free-signed-ssl-certificate-on-a-vps
Note: You may want to consider using Let's Encrypt instead of the StartSSL.com process below. Let's Encrypt is a new certificate authority that provides a free and easy way of creating SSL/TLS certificates that are trusted in most web browsers. Check out the tutorial to get started: How To Secure Apache with Let's Encrypt on Ubuntu 14.04

Prerequisites

Before we get started, here are the web tools you need for this tutorial:

  1. Google Chrome browser
  2. Apache installed on your VPS (cloud server)
  3. A domain name you own
  4. Access to an email address at that domain, either:
    1. postmaster@duable.co
    2. hostmaster@duable.co
    3. webmaster@duable.co

StartSSL.com offers completely free verified (your users won't have to see those scary red screens saying "this site isn't trusted" anymore) SSL certificates that you can use on your website. This is a great deal as most companies charge $50-$60 for similar services. The free version is a bit tricky to set up, but it's well worth it.

To get started, browse to StartSSL.com and using the toolbar on the left, navigate to StartSSL Products and then to StartSSL™ Free. Choose the link for Control Panel from the top of the page.

Make sure you are using Google Chrome

  1. Choose the Express Signup. option
  2. Enter your personal information, and click continue.
  3. You'll get an email with a verification code inside it shortly. Copy and paste that email into the form on StartSSL's page.
  4. They will review your request for a certificate and then send you an email with the new info. This process might take as long as 6 hours though, so be patient.
  5. Once the email comes, use the link provided and the new authentication code (at the bottom of the email) to continue to the next step.
  6. They will ask you to Generate a private key and you will be provided with the choice of "High" or "Medium" grade. Go ahead and choose "High".
  7. Once your key is ready, click Install.
  8. Chrome will show a popdown that says that the certificate has been succesfully installed to Chrome.

This means your browser is now authenticated with your new certificate and you can log into the StartSSL authentication areas using your new certificate. Now, we need to get a properly formatted certificate set up for use on your VPS. Click on the Control panel link again, and choose the Authenticate option. Chrome will show a popup asking if you want to authenticate and will show the certificate you just installed. Go ahead and authenticate with that certificate to enter the control panel.

You will need to validate your domain name to prove that you own the domain you are setting up a certificate for. Click over to the Validations Wizard in the Control panel and set Type to Domain Name Validation. You'll be prompted to choose from an email at your domain, something like [email]postmaster@yourdomain.com[/email].

StartSSL

Check the email inbox for the email address you selected. You will get yet another verification email at that address, so like before, copy and paste the verification code into the StartSSL website.

Next, go to the Certificates Wizard tab and choose to create a Web Server SSL/TLS Certificate.

Start SSL

Hit continue and then enter in a secure password, leaving the other settings as is.

You will be shown a textbox that contains your private key. Copy and paste the contents into a text editor and save the data into a file called ssl.key.

Private Key

When you click continue, you will be asked which domain you want to create the certificate for:

Choose Domain

Choose your domain and proceed to the next step.

You will be asked what subdomain you want to create a certificate for. In most cases, you want to choose www here, but if you'd like to use a different subdomain with SSL, then enter that here instead:

Add Subdomain

StartSSL will provide you with your new certificate in a text box, much as it did for the private key:

Save Certificate

Again, copy and paste into a text editor, this time saving it as ssl.crt.

You will also need the StartCom Root CA and StartSSL's Class 1 Intermediate Server CA in order to authenticate your website though, so for the final step, go over to the Toolbox pane and choose StartCom CA Certificates:

Startcome CA Certs

At this screen, right click and Save As two files:

  • StartCom Root CA (PEM Encoded) (save to ca.pem)
  • Class 1 Intermediate Server CA (save to sub.class1.server.ca.pem)

For security reasons, StartSSL encrypts your private key (the ssl.key file), but your web server needs the unencrypted version of it to handle your site's encryption. To unencrypt it, copy it onto your server, and use the following command to decrypt it into the file private.key:

openssl rsa -in ssl.key -out private.key

OpenSSL will ask you for your password, so enter it in the password you typed in on StartSSL's website.

At this point you should have five files. If you're missing any, double-check the previous steps and re-download them:

  • ca.pem - StartSSL's Root certificate
  • private.key - The unencrypted version of your private key (be very careful no one else has access to this file!)
  • sub.class1.server.ca.pem - The intermediate certificate for StartSSL
  • ssl.key - The encrypted version of your private key (does not need to be copied to server)
  • ssl.crt - Your new certificate

You can discard the ssl.key file. If you haven't already copied the others onto your server you upload them there now:

scp {ca.pem,private.key,sub.class1.server.ca.pem,ssl.crt} YOURSERVER:~ 6 W/ `, X0 e  X- {, V

Activating the certificate in Apache

Having a certificate isn't any good if you can't actually use it. This section explains how to configure Apache to use your new SSL certificate. These instructions are for Apache running on recent versions of Ubuntu VPS. For other Linux-based distros or web servers, you'll have to adjust accordingly.

First, create the folders where we'll store the keys. Enable Apache's SSL module, and restart Apache.

sudo a2enmod ssl3 ?7 _. h7 q$ [
sudo service apache2 restart  B- n; s3 g4 `! A, k7 X* [
sudo mkdir -p /etc/apache2/ssl0 F! |! g" _* A6 x$ O, s

Copy the files you set up in the previous section into the /etc/apache2/ssl folder on your VPS.

sudo mkdir -p /etc/apache2/ssl% ]' d& g0 {8 X
cp ~/{ca.pem,private.key,sub.class1.server.ca.pem,ssl.crt} /etc/apache2/ssl9 y  z7 z8 k6 K5 t! A4 O2 q

Execute:

ls /etc/apache2/ssl

And it should return:

ca.pem2 r' L! Z5 k- _7 g9 Q
ssl.crt2 H& Z$ j+ e1 g3 y
private.key! c( i% ?' {, T. E* I  A. `( J. d
sub.class1.server.ca.pem

Now, open your apache2 configuration file. Unless you've already modified the default configuration, input:

nano /etc/apache2/sites-enabled/000-default

It should look something like this:

<VirtualHost *:80>- k' I8 T; V( o, Z# k5 W) ^
    ServerAdmin webmaster@localhost; J2 D( L: n# Z

9 `& A8 H, r" o) _& r9 P3 X! B$ g) [    DocumentRoot /var/www* F. _. l+ [' n( b+ U7 B
    <Directory />
/ f4 i& s3 y% [, B$ s! m9 u. }+ P        Options FollowSymLinks
  f7 L6 O) A, l( l        AllowOverride None
0 L' O2 A3 s( d" ]# ?    </Directory>  `6 L( E1 k3 L2 m* K4 o# l( [
    <Directory /var/www/>2 _) j$ ~1 w6 ]. c8 M! T+ T0 N
        Options Indexes FollowSymLinks MultiViews
2 @3 [9 f$ V1 ]3 P; O        AllowOverride None
7 S& Z8 R2 _6 ^- j        Order allow,deny# j, }# i  T+ b5 V- W. Z; G
        allow from all
7 y" @7 u. S) c8 e$ ]    </Directory>: C2 z( g$ a# |/ \) W- J

+ b. P7 C& z$ A. r    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/4 t6 i5 z5 g- x& W9 l" O
    <Directory "/usr/lib/cgi-bin">
) s8 u3 Y8 Y1 L( t8 B        AllowOverride None6 W; z, l0 S3 w8 C0 ^9 ]7 |# F. p, m
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
4 S4 w! H& ?, k( Q4 N8 o- n        Order allow,deny3 Y4 S' s- M& q0 Y3 H3 s1 i
        Allow from all
! H0 S5 i( F1 K, F% R4 }    </Directory>
2 d/ M- n' x: G* X7 W4 c+ i, Z5 B! {
    ErrorLog ${APACHE_LOG_DIR}/error.log
$ N& K  r5 v, d( Y/ |1 S% E1 a8 Q# O4 h+ F8 m  O
    # Possible values include: debug, info, notice, warn, error, crit,2 \/ h. v; d# `* s/ s& W6 m
    # alert, emerg.
4 u2 U5 P9 X) _1 `: A5 i( E4 w. N    LogLevel warn
/ C1 F2 Y) e/ Y- u
2 D( _) z; Y/ p7 {3 d2 e- i9 G$ t7 p    CustomLog ${APACHE_LOG_DIR}/access.log combined& r* e/ ?5 Y0 R: y9 n/ }

+ L7 `# Y6 H4 a5 {$ h) N$ ^    Alias /doc/ "/usr/share/doc/"
6 s0 ~3 c4 Q* X/ N7 O% G, m* V, H    <Directory "/usr/share/doc/">. t4 V* b1 V# a# u/ |
        Options Indexes MultiViews FollowSymLinks
4 H& I5 u6 H+ X- S: [7 G% O# e        AllowOverride None9 J. I3 d1 K: S( ]3 O# e
        Order deny,allow
6 Z" w: o! @8 G: k) r4 |$ v: ~' y        Deny from all
1 G9 S$ b- b2 q/ K- o( E. i        Allow from 127.0.0.0/255.0.0.0 ::1/128
5 X9 D9 G" o6 ?8 L; D* U$ s    </Directory>* J+ B: G; F5 Z* N
/ f! }) t) M" l
</VirtualHost>7 }- |0 A& x: z

Copy the entire script above (from <VirtualHost *:80> to </VirtualHost>), paste it below the existing one, and change the top line from:

<VirtualHost *:80>

to

<VirtualHost *:443>

And add the following lines after the <VirtualHost *:443> line:

SSLEngine on                                                                
2 a7 ~0 C# k: b* a0 i8 s. [SSLProtocol all -SSLv2                                                      
9 c. q# b3 z: G6 }SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM                9 ^! p5 p. n+ C6 ^7 {
1 F) l' s) a( K
SSLCertificateFile /etc/apache2/ssl/ssl.crt                           
" H3 i6 l* z9 R; U1 P9 USSLCertificateKeyFile /etc/apache2/ssl/private.key                        
+ g. u, p+ [% o3 W8 uSSLCertificateChainFile /etc/apache2/ssl/sub.class1.server.ca.pem 

The end result should look like this:

<VirtualHost *:80>. e5 u* u& x' f/ O& O; N
    ServerAdmin webmaster@localhost) F( h, Z" g" y! K, M, I
: e0 g# m0 |( R; k, r: H2 }' s, ^( i
    DocumentRoot /var/www
+ k& `& F; y% [5 u1 y; S+ G- S4 M4 {    <Directory />
9 N6 w: c% C/ z        Options FollowSymLinks  V& X5 t3 C. X( z" j4 E  l7 w8 W
        AllowOverride None3 f) O$ @, N6 V$ ]8 P- a1 l
    </Directory>
- `5 W. ?+ a, w4 n& m    <Directory /var/www/>+ P9 V! v5 k+ S, T+ A. b
        Options Indexes FollowSymLinks MultiViews4 ^* ~+ d3 p7 m; o' m' X9 k
        AllowOverride None) \) j3 r% ~# k8 W) }6 g
        Order allow,deny6 [+ S$ s7 i- E, L$ o
        allow from all
) a9 A) }  B- _4 O2 E8 T+ |8 \" B    </Directory>) a1 U& W; J1 x
0 I7 W: x" u8 [' Q8 Q
    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/+ z3 D" k) D$ ^
    <Directory "/usr/lib/cgi-bin">
4 c8 \1 e0 }  k% V7 `        AllowOverride None
* c2 q' B8 K/ O        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
5 |* m' {6 G  c1 s5 h: ]        Order allow,deny
) f* |4 b! ]5 ~2 H+ n- w        Allow from all, c& g1 t1 \* X
    </Directory>( l8 L/ w9 l$ v0 s. H
9 ?' L5 ^- K2 W
    ErrorLog ${APACHE_LOG_DIR}/error.log" Y' E# y, \+ Y% E/ h$ [$ k" y
  k! i( E- [4 ]' l6 H" d
    # Possible values include: debug, info, notice, warn, error, crit,( P( e4 m% B' z4 Q  Z( O2 p" @$ @
    # alert, emerg.
" c* E9 B! v% `  X& i% T  {    LogLevel warn  F1 p( m4 i" L: ?! s
/ v% y- c0 M9 y
    CustomLog ${APACHE_LOG_DIR}/access.log combined
, P' n, @  ^7 ]  i2 i% |" @" c. {
    Alias /doc/ "/usr/share/doc/"
/ Y2 {7 I; y3 ~6 r9 D; C    <Directory "/usr/share/doc/">
" k' b" u- G3 F/ ?. R( i$ L- p        Options Indexes MultiViews FollowSymLinks# m* ^* S+ p* `- J: @; `
        AllowOverride None
1 P4 k7 i6 E2 n2 b% i3 u# b        Order deny,allow& E( ?2 v" V* y1 V. f8 S
        Deny from all5 t7 t9 i/ N1 ]/ Z. H1 U& ^) F
        Allow from 127.0.0.0/255.0.0.0 ::1/128
* j: B4 x2 t5 g9 I3 W4 U* T    </Directory>
# R6 Z6 U, O8 m0 B$ d3 b0 L) f9 @, ?% z0 j
</VirtualHost>) T8 s: z3 I" Z
  ?* L* Y9 m1 P4 o5 w" T
<VirtualHost *:443>
7 z# S: L: A) a' R+ N' o    SSLEngine on                                                                / i  ~( v% F4 M5 O
    SSLProtocol all -SSLv2                                                      % r6 A; F! I+ V0 _
    SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM                * u# g: b& e7 v2 n. O

0 T. T0 @0 f: q4 l" @6 ?  l% s    SSLCertificateFile /etc/apache2/ssl/ssl.crt                           " L  g9 [; c7 O% _7 V9 c
    SSLCertificateKeyFile /etc/apache2/ssl/private.key                        
9 w2 B% U% e% y% ~  j    SSLCertificateChainFile /etc/apache2/ssl/sub.class1.server.ca.pem 
! T) d) N; Z) u( K. z$ `    ServerAdmin webmaster@localhost, t9 W0 L1 b+ m) |: g

: i; T& z9 w1 y    DocumentRoot /var/www9 i4 _5 m- t. W
    <Directory />
0 y- c0 Z: B$ \# f/ m0 y# A4 y: f        Options FollowSymLinks
* m% \! o, y, ~8 M- |- d4 M2 Q( _; A        AllowOverride None' X9 r; f: [1 g+ ^0 p/ a  A8 A
    </Directory>
/ Q! @8 W  i% V4 q5 d9 R    <Directory /var/www/>  @, q7 Q4 t% m1 ~, W  ~9 Y
        Options Indexes FollowSymLinks MultiViews) U% w" f- h/ ?
        AllowOverride None
. T4 I  d4 A  B4 ]  b) Z' a6 M        Order allow,deny1 w, F6 l! i) W; E/ f: Q
        allow from all- Z# C2 \7 @0 ?, {& G
    </Directory># F' a8 H4 z7 M6 r

0 R; l2 S6 e& P6 i0 {8 s5 k    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
4 I) T, R2 b- _    <Directory "/usr/lib/cgi-bin">
* K% A$ @. B, {6 v        AllowOverride None$ I. j$ s' @5 r; ?
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch) r9 S& o! D) v, m" y: c" H
        Order allow,deny5 Z. n9 b  X" h$ L3 h5 b: Z7 R
        Allow from all
5 ~/ r4 j4 l' g2 H' t    </Directory>$ ^$ y! e1 V) J* S) M' D8 s' Y) Y
0 P; U( x/ O5 q% ]( ^; M* `! {& C
    ErrorLog ${APACHE_LOG_DIR}/error.log
0 \* r9 s: P5 j7 |: e- ?
  |; K1 f! R: {+ O$ V    # Possible values include: debug, info, notice, warn, error, crit,* I( U  }& s0 L; c- [3 t
    # alert, emerg.1 h! [* o. v3 W# |& J- P( @" `6 ~
    LogLevel warn+ Q! m! Z1 F+ G& w

7 ~& K5 w6 ^8 W" v! l3 N    CustomLog ${APACHE_LOG_DIR}/access.log combined# ?  C) n5 U+ d7 ^5 U8 L; H
- i) O6 f" W7 n
    Alias /doc/ "/usr/share/doc/"  b6 V& _# {2 D( |' p% O
    <Directory "/usr/share/doc/">
9 {- Y6 V7 Z& t  }* L; F        Options Indexes MultiViews FollowSymLinks: W: v: V. W7 v
        AllowOverride None
7 p6 a  z2 B. K' U4 e        Order deny,allow; P+ k' ?% K- B- Y* V& Y5 F0 L
        Deny from all  g( o! R( E, q1 a" y
        Allow from 127.0.0.0/255.0.0.0 ::1/128* G* O8 {- D/ y4 J/ T
    </Directory>' l: T8 o, F$ Y! U' i3 C# k
! @# n$ n; z# B7 l( `' O/ i
</VirtualHost>

Save your files and restart Apache with:

sudo service apache2 restart

You can check Apache's log files to see if there are any show stopping errors with this command:

cat /var/log/apache2/error.log. ?& x$ g- F4 X; n

If everything looks good, try accessing your site in your web browser using an HTTPS URL (e.g. https://www.YOURSITE.com). When your site loads, you should see a little green padlock icon next to the URL. Click on it and you should see the following. The connections tab should show that the site's identity has been verified by StartCom.

Congratulations! You are all set!

Reference Links:

Here are some of the other posts I consulted when putting this together. If you run into any problems they might be a source of inspiration on how to fix them:

地板
发表于 2017-4-6 12:02 | 只看该作者
How To Secure Apache with Let's Encrypt on Ubuntu 14.04https://www.digitalocean.com/community/tutorials/how-to-secure-apache-with-let-s-encrypt-on-ubuntu-14-04, ^' _% N) B. l7 I7 l
; P$ \+ z7 K# ?

  \5 F7 y  L& K2 L2 |8 HIntroduction

This tutorial will show you how to set up a TLS/SSL certificate from https://letsencrypt.org/ on an Ubuntu 14.04 server running Apache as a web server. We will also cover how to automate the certificate renewal process using a cron job.

SSL certificates are used within web servers to encrypt the traffic between the server and client, providing extra security for users accessing your application. Let’s Encrypt provides an easy way to obtain and install trusted certificates for free.

/ ^% s5 w" y" P, `- F3 W
Prerequisites

In order to complete this guide, you will need:

  • An Ubuntu 14.04 server with a non-root sudo user, which you can set up by following our https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-14-04 guide
  • The Apache web server installed with https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts properly configured- ^. ~! k0 E& k' ?5 O) ^

When you are ready to move on, log into your server using your sudo account.

$ W/ h& k* U: @) I) `4 m
Step 1 — Download the Let’s Encrypt Client

First, we will download the certbot-auto Let’s Encrypt client from the EFF download site. The client will automatically pull down available updates as necessary after installation.

We can download the certbot-auto Let’s Encrypt client to the /usr/local/sbin directory by typing:

  • cd /usr/local/sbin
  • sudo wget https://dl.eff.org/certbot-auto+ A* T0 h% `1 s+ X( G, r

You should now have a copy of certbot-auto in the /usr/local/sbin directory.

Make the script executable by typing:

  • sudo chmod a+x /usr/local/sbin/certbot-auto
    ! y$ _6 ]+ H- r# b

The certbot-auto client should now be ready to use.


# p! _; ?2 N- ]9 Z) BStep 2 — Set Up the SSL Certificate

Generating the SSL Certificate for Apache using the certbot-auto Let’s Encrypt client is quite straightforward. The client will automatically obtain and install a new SSL certificate that is valid for the domains provided as parameters.

To execute the interactive installation and obtain a certificate that covers only a single domain, run the certbot-auto command with:

  • certbot-auto --apache -d example.com: _" N6 L/ K) W1 c0 T2 K

If you want to install a single certificate that is valid for multiple domains or subdomains, you can pass them as additional parameters to the command. The first domain name in the list of parameters will be the base domain used by Let’s Encrypt to create the certificate, and for that reason we recommend that you pass the bare top-level domain name as first in the list, followed by any additional subdomains or aliases:

  • certbot-auto --apache -d example.com -d www.example.com
    % H( _8 L) z- I6 L  z: L

For this example, the base domain will be example.com.

After the dependencies are installed, you will be presented with a step-by-step guide to customize your certificate options. You will be asked to provide an email address for lost key recovery and notices, and you will be able to choose between enabling both http and https access or force all requests to redirect to https.

When the installation is finished, you should be able to find the generated certificate files at /etc/letsencrypt/live. You can verify the status of your SSL certificate with the following link (don’t forget to replace example.com with your base domain):

https://www.ssllabs.com/ssltest/analyze.html?d=example.com&latest

You should now be able to access your website using a https prefix.

8 [7 l  k- X; n1 K) v: J
Step 3 — Set Up Auto Renewal

Let’s Encrypt certificates are valid for 90 days, but it’s recommended that you renew the certificates every 60 days to allow a margin of error. The certbot-auto Let's Encrypt client has a renew command that automatically checks the currently installed certificates and tries to renew them if they are less than 30 days away from the expiration date.

To trigger the renewal process for all installed domains, you should run:

certbot-auto renew

Because we recently installed the certificate, the command will only check for the expiration date and print a message informing that the certificate is not due to renewal yet. The output should look similar to this:

Checking for new version...Requesting root privileges to run letsencrypt...   /home/sammy/.local/share/letsencrypt/bin/letsencrypt renewProcessing /etc/letsencrypt/renewal/example.com.confThe following certs are not due for renewal yet:  /etc/letsencrypt/live/example.com/fullchain.pem (skipped)No renewals were attempted.

Notice that if you created a bundled certificate with multiple domains, only the base domain name will be shown in the output, but the renewal should be valid for all domains included in this certificate.

A practical way to ensure your certificates won’t get outdated is to create a cron job that will periodically execute the automatic renewal command for you. Since the renewal first checks for the expiration date and only executes the renewal if the certificate is less than 30 days away from expiration, it is safe to create a cron job that runs every week or even every day, for instance.

Let's edit the crontab to create a new job that will run the renewal command every week. To edit the crontab for the root user, run:

  • sudo crontab -e
    & M2 F' V# z1 O4 K: v

Include the following content, all in one line:

[color=rgba(0, 0, 0, 0.298039)]crontab
; r+ e( L) M: }7 C30 2 * * 1 /usr/local/sbin/certbot-auto renew >> /var/log/le-renew.log

Save and exit. This will create a new cron job that will execute the letsencrypt-auto renew command every Monday at 2:30 am. The output produced by the command will be piped to a log file located at /var/log/le-renewal.log.

For more information on how to create and schedule cron jobs, you can check our https://www.digitalocean.com/community/tutorials/how-to-use-cron-to-automate-tasks-on-a-vps guide.

' F+ t& e; y6 O6 l1 E. U

: P" Z2 |2 @( Z1 ]& o8 h
5#
发表于 2017-4-6 12:06 | 只看该作者
How To Use Cron To Automate Tasks On a VPS
% s9 a7 H, k: A/ F2 \! ?https://www.digitalocean.com/community/tutorials/how-to-use-cron-to-automate-tasks-on-a-vps1 F% v% D' z' x

3 i7 Q3 k; j9 x. Q7 dIntroduction

One of the most standard ways to run tasks in the background on Linux machines is with cron jobs. They’re useful for scheduling tasks on the VPS and automating different maintenance-related jobs. “Cron” itself is a daemon (or program) that runs in the background. The schedule for the different jobs that are run is in a configuration file called “crontab.”

" Y$ p6 a7 M2 c! R1 O
Installation

Almost all distros have a form of cron installed by default. However, if you’re using a system that doesn’t have it installed, you can install it with the following commands:

For Ubuntu/Debian:

sudo apt-get updatesudo apt-get install cron

For Cent OS/Red Hat Linux:

sudo yum updatesudo yum install vixie-cron crontabs

You’ll need to make sure it runs in the background too:

sudo /sbin/chkconfig crond onsudo /sbin/service crond start" i! s( l$ `  ^8 M$ K7 U) f
Syntax

Here is an example task we want to have run:

5 * * * * curl http://www.google.com

The syntax for the different jobs we’re going to place in the crontab might look intimidating. It’s actually a very succinct and easy-to-parse if you know how to read it. Every command is broken down into:

  • Schedule
  • Command
    # w( t5 ^9 t0 K6 e# M3 h6 D

The command can be virtually any command you would normally run on the command line. The schedule component of the syntax is broken down into 5 different options for scheduling in the following order:

  • minute
  • hour
  • day of the month
  • month
  • day of the week5 v$ D, e9 y6 h
- @, A" }) m2 C0 q6 D5 J: |5 k
Examples

Here is a list of examples for some common schedules you might encounter while configuring cron.

To run a command every minute:

* * * * *

To run a command every 12th minute on the hour:

12 * * * *

You can also use different options for each placeholder. To run a command every 15 minutes:

0,15,30,45 * * * *

To run a command every day at 4:00am, you’d use:

0 4 * * *

To run a command every Tuesday at 4:00am, you’d use:

0 4 * * 2

You can use division in your schedule. Instead of listing out 0,15,30,45, you could also use the following:

*/4 2-6 * * *

Notice the “2-6” range. This syntax will run the command between the hours of 2:00am and 6:00am.

The scheduling syntax is incredibly powerful and flexible. You can express just about every possible time imaginable.

- M' f1 V3 F3 G8 d$ ~2 `( @7 m
Configuration

Once you’ve settled on a schedule and you know the job you want to run, you’ll have to have a place to put it so your daemon will be able to read it. There are a few different places, but the most common is the user’s crontab. If you’ll recall, this is a file that holds the schedule of jobs cron will run. The files for each user are located at /var/spool/cron/crontab, but they are not supposed to be edited directly. Instead, it's best to use the crontab command.

You can edit your crontab with the following command:

crontab -e

This will bring up a text editor where you can input your schedule with each job on a new line.

If you’d like to view your crontab, but not edit it, you can use the following command:

crontab -l

You can erase your crontab with the following command:

crontab -r

If you’re a privileged user, you can edit another user’s by specifying crontab -u <user> -e


- f8 t$ y3 Y. c9 H+ @! qOutput

For every cron job that gets executed, the user’s email address that’s associated with that user will get emailed the output unless it is directed into a log file or into /dev/null. The email address can be manually specified if you provide a “MAILTO” setting at the top of the crontab. You can also specify the shell you’d like run, the path where to search for the cron binary and the home directory with the following example:

First, let’s edit the crontab:

crontab -e

Then, we’ll edit it like so:

SHELL=/bin/bashHOME=/MAILTO=”[email]example@digitalocean.com[/email]”#This is a comment* * * * * echo ‘Run this command every minute’

This particular job will output "Run this command every minute." That output will get emailed every minute to the “mailto:example@digitalocean.com” email address I specified. Obviously, that might not be an ideal situation. As mentioned, we can also pipe the output into a log file or into an empty location to prevent getting an email with the output.

To append to a log file, it’s as simple as:

* * * * * echo ‘Run this command every minute’ >> file.log

Note: “>>” appends to a file.

If you want to pipe into an empty location, use /dev/null. Here is a PHP script that gets executed and runs in the background.

* * * * * /usr/bin/php /var/www/domain.com/backup.php > /dev/null 2>&1; r  t/ |3 {, z- S7 h
Restricting Access

Restricting access to cron is easy with the /etc/cron.allow and /etc/cron.deny files. In order to allow or deny a user, you just need to place their username in one of these files, depending on the access required. By default, most cron daemons will assume all users have access to cron unless one of these file exists. To deny access to all users and give access to the user tdurden, you would use the following command sequence:

echo ALL >>/etc/cron.denyecho tdurden >>/etc/cron.allow

First, we lock out all users by appending "ALL" to the deny file. Then, by appending the username to the allow file, we give the user access to execute cron jobs.


: _+ r9 y6 J+ y7 ?- cSpecial Syntax

There are several shorthand commands you can use in your crontab file to make administering a little easier. They are essential shortcuts for the equivalent numeric schedule specified:

  • @hourly - Shorthand for 0 * * * *
  • @daily - Shorthand for 0 0 * * *
  • @weekly - Shorthand for 0 0 * * 0
  • @monthly - Shorthand for 0 0 1 * *
  • @yearly - Shorthand for 0 0 1 1 *8 Z8 w; D, O" v/ p1 y

and @reboot, which runs the command once at startup.

Note: Not all cron daemons can parse this syntax (particularly older versions), so double-check it works before you rely on it.

To have a job that runs on start up, you would edit your crontab file (crontab -e) and place a line in the file similar to the following:

@reboot echo "System start up"

This particular command would get executed and then emailed out to the user specified in the crontab.

+ S0 _, j6 \4 z5 S6 U5 k4 k
: ?! S4 }. t* j3 ~  j# g4 C: s& n
6#
发表于 2017-4-6 12:10 | 只看该作者
https://debian-administration.org/article/349/Setting_up_an_SSL_server_with_Apache2
; M8 [# j/ ~5 W2 K& E
8 J" C# f' t5 eSetting up an SSL server with Apache2
( A/ c" O8 a. ^4 O& y- v! h" K1 I9 |5 P) ]
With the introduction of the Apache2 packages in Debian it is much simpler to create and use a secure SSL protected webserver than in the old days http://www.debian-administration.org/articles/31, here we'll show how it is done.
If you have Apache 2.x installed already then you're good to go as you don't need anything extra installed.
If you haven't got it installed then you can do so easily:
earth:~# apt-get install apache2Reading Package Lists... DoneBuilding Dependency Tree... DoneThe following extra packages will be installed:  apache2-common apache2-mpm-worker apache2-utils openssl ssl-certSuggested packages:  apache2-doc ca-certificatesThe following NEW packages will be installed:  apache2 apache2-common apache2-mpm-worker apache2-utils openssl ssl-cert0 upgraded, 6 newly installed, 0 to remove and 0 not upgraded.Need to get 2040kB of archives.After unpacking 6218kB of additional disk space will be used.Do you want to continue? [Y/n]
Once the server is installed you need to do three things to get a working SSL setup:
  • Generate, or import, a certificate.
  • Enable Apaches SSL support.
  • Configure your SSL options.
    ! T( ]3 @% v9 g) Y, ]
Generating A Certificate
Generating a certificate from scratch will give you something which will be used to protect the traffic exchanged between clients and your server, however it will be signed by a untrusted certificate authority so it will generate warnings.
Importing a paid and "trusted" certificate will avoid this problem, but that is beyond the scope of this simple introduction.
Generating an SSL certificate for Apache2 may be accomplished using the apache2-ssl-certificate script. This will ask you questions interactively then generate the certificate file appropriately.
Here's a sample session:
earth:~# apache2-ssl-certificatecreating selfsigned certificatereplace it with one signed by a certification authority (CA)enter your ServerName at the Common Name promptIf you want your certificate to expire after x days call this programmwith -days xGenerating a 1024 bit RSA private key............++++++..........................++++++writing new private key to '/etc/apache2/ssl/apache.pem'-----You are about to be asked to enter information that will be incorporatedinto your certificate request.What you are about to enter is what is called a Distinguished Name or a DN.There are quite a few fields but you can leave some blankFor some fields there will be a default value,If you enter '.', the field will be left blank.-----Country Name (2 letter code) [GB]:State or Province Name (full name) [Some-State]:ScotlandLocality Name (eg, city) []:EdinburghOrganization Name (eg, company; recommended) []:Steve KempOrganizational Unit Name (eg, section) []:server name (eg. ssl.domain.tld; required!!!) []:earthEmail Address []: [email]earth-admin@steve.org.uk[/email]
Enabling SSL Support
To use the SSL facilities of Apache2 you must enable the module mod_ssl, this can be achieved using the helper tool a2enmod (We've previously http://www.debian-administration.org/articles/207.)
As root run:
earth:~# a2enmod sslModule ssl installed; run /etc/init.d/apache2 force-reload to enable.
Once this is done you'll have Apache setup to accept SSL connections, but the server will still only be listening for incoming HTTP requests on port 80 - and not SSL connections on port 443. To fix this you must add a line to the file /etc/apache2/ports.conf:
Listen 443
With these two steps out of the way you now have an Apache setup which will listen for and accept SSL connections. The next step is to modify your virtualhosts to use it.
Configuring your SSL Hosts
With a certificate setup, and the server updated to load and listen for incoming SSL connections you're almost finished. The final step is to ensure that your virtual hosts, or main host, will accept SSL options.
I use virtual hosts upon my machine and this just means adding a couple of options to each one I wish to use SSL:
SSLEngine onSSLCertificateFile /etc/apache2/ssl/apache.pem
For reference here is a complete example which should be easy to modify/understand:
NameVirtualHost *:443NameVirtualHost *:80<VirtualHost *:80>        ServerName earth.my.flat        DocumentRoot /var/www/        ErrorLog /var/log/apache2/error.log        CustomLog /var/log/apache2/access.log combined</VirtualHost><VirtualHost *:443>        ServerName earth.my.flat        DocumentRoot /var/www/        ErrorLog /var/log/apache2/error.log        CustomLog /var/log/apache2/access.log combined        SSLEngine on        SSLCertificateFile /etc/apache2/ssl/apache.pem</VirtualHost>' P3 f: H0 @2 P4 |; u1 e
7#
发表于 2017-4-6 12:12 | 只看该作者
Redirect HTTP to HTTPS automatically" \* K4 B' {4 ], T  ^& F
https://ca.godaddy.com/help/redirect-http-to-https-automatically-8828
& d/ E3 Y7 N2 T& S$ x- o& F$ e: W5 G  X$ |
0 s9 j# N6 U2 T5 Z' r4 z' a. ^
If you have a secure certificate (SSL) on your website, you can automatically redirect visitors to the secured (HTTPS) version of your website to make sure their information is protected.
How you redirect traffic depends on https://ca.godaddy.com/help/what-type-of-hosting-account-do-i-have-6971.
Linux & cPanel
Linux-based accounts use .htaccess files to handle redirection.
If you need to create a .htaccess file, you can use your control panel's file manager (https://ca.godaddy.com/help/managing-your-hosting-accounts-files-12426 / https://ca.godaddy.com/help/create-files-16278).
Using the following code in your .htaccess file automatically redirects visitors to the HTTPS version of your site:
RewriteEngine OnRewriteCond %{HTTPS} offRewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
If you have an existing .htaccess file:
  • Do not duplicate RewriteEngine On.
  • Make sure the lines beginning RewriteCond and RewriteRule immediately follow the already-existing RewriteEngine On.
    " u: v4 \$ B& D+ f3 \# U  F
Windows & Plesk
Windows-based accounts use web.config files to handle redirection.
If you need to create a web.config file, you can use your control panel's file manager (https://ca.godaddy.com/help/managing-your-hosting-accounts-files-12426 / https://ca.godaddy.com/help/create-files-16279).
Using the following code in your web.config file automatically redirects visitors to the HTTPS version of your site:
<configuration><system.webServer><rewrite>    <rules>        <rule name="HTTP to HTTPS redirect" stopProcessing="true">         <match url="(.*)" />         <conditions>                 <add input="{HTTPS}" pattern="off" ignoreCase="true" />        </conditions>         <action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" /></rule>       </rules></rewrite></system.webServer></configuration>
If you have an existing web.config file:
  • Ensure you have sections (i.e. opening and closing tags) for:
    • system.webServer (which contains rewrite)
    • rewrite (which contains rules)
    • rules (which contains one or more rule sections)' V7 j/ L& v, z3 z& o, R
    Insert any of those sections that do not exist.
  • Insert the entire rule section, including match, conditions, and action, inside the rules section.
    You're inserting the rule (without an 's') inside the rules (with an 's') section.
    ( d8 r. s5 X6 i

* a1 M) d5 A. g% R6 ]5 W3 Q7 K% @- x8 J4 g4 t6 F  a
8#
发表于 2017-4-6 14:51 | 只看该作者
DISCUZ x3.2 开启301强制跳转https后 门户栏目出现302死循环1 J  J( L  m1 C; g6 K5 {
) W( Y( @8 X/ M+ r% s7 I

" s7 n( Q8 m2 O+ [自己测试figureed out:1 }' e: _+ A3 [9 D

7 P4 {: j3 W( I/ X- \, K/ M1:全局---域名设置---应用域名---全部清除
! }5 w% {! q. M; V5 L/ m# M# U3 [5 B( M
2:全局---域名设置----根域名设置---频道---留空) v: M$ V# V0 `% Z) |( h
# o* E# i, Z# V0 _# y9 Z

& d) r, O! J) F. n) M& ?也可参考:
  @6 }% A+ c& j" a, a: D8 V9 L4 z% \: Y. ^. c1 P+ {, ~
DISCUZ x3.2 开启301强制跳转https后 门户栏目出现302死循环- k# k& Q3 i/ [; x2 x8 Y: @

5 S3 T! M; D' w* N  W: }; phttp://bbs.zhanzhang.baidu.com/thread-166634-1-1.html$ x% p, V+ {& R( h/ K
" c/ H* b# _1 ~0 q, h; V# E8 m
2 _& W$ C. w2 n. n' a8 H( L7 f
此方法并不能彻底解决此问题,正确解决方案:" I9 V/ s3 i3 w$ {) S
+ M: }8 r4 U( Z+ ~
用最新版DiscuzX3.3的方法移植3.2上面即可解决
' U+ Q6 h; t6 x打开
! ]% |! Q4 c0 H7 t4 E9 L- k* `# `source/function/cache/cache_portalcategory.php
/ C& g6 p- e' K9 p4 w4 o查找
( g& R- b. x! Z. d4 y: v! W2 p. z
  • $portaldomain = 'http://'.$domain['app']['portal'].$_G['siteroot'];
    $ x" L- I# b+ v5 x6 Z' P

- `( m" w4 c8 {: S, S[color=rgb(51, 102, 153) !important]复制代码
, I) ~1 Q" C  h$ G+ O
替换为9 l% \! L* @" H; R& c- M
  • $portaldomain = $_G['scheme'].'://'.$domain['app']['portal'].$_G['siteroot'];! B) p- q/ B7 {' ]. j2 l5 z3 a

, h: p. w# S3 F! o3 ?) y7 i5 Y2 K[color=rgb(51, 102, 153) !important]复制代码
% A* F* _- m% L* D' P
0 _  q" l" P/ o9 d, Y- F" i# E
. ^' \. [3 z6 z4 v; d
查找
2 y7 g) t7 d0 g# _6 e4 o) [% p& S+ J! S* o
  • $portaldomain = 'http://'.$domain['app']['default'].$_G['siteroot'];# ]9 I* r; B4 i5 ~* T7 f
+ E1 I3 c! h* G+ u2 R: E* e8 Y1 A
[color=rgb(51, 102, 153) !important]复制代码

- o! m. I: H1 ]! b1 d! {% ~替换为
8 q3 @0 T0 \. e( A! p3 F- V* |
  • $portaldomain = $_G['scheme'].'://'.$domain['app']['default'].$_G['siteroot'];
    % u  Y) v3 C4 L7 Q+ b

. H# f3 n6 T$ H( V[color=rgb(51, 102, 153) !important]复制代码

2 X1 u* t$ H3 D# V4 [8 T! H' r* H8 K$ v- O
+ @9 c! z6 k, m* k7 F( ~: F' G
查找2 _- m" K4 N7 G9 N( y$ T
  • $url = 'http://'.$data[$topid]['domain'].'.'.$channelrootdomain.'/';
      [2 W) _% t# ~
- x" Y9 |  _4 \* w9 {% \6 L& [
[color=rgb(51, 102, 153) !important]复制代码

6 ]" u; X/ g7 s+ b替换为: s2 H5 c- X1 ^  c, s0 O( w
  • $url = $_G['scheme'].'://'.$data[$topid]['domain'].'.'.$channelrootdomain.'/';( `+ D4 S% R! {% c

- W0 ~% K  Q  [! N" V2 h% o[color=rgb(51, 102, 153) !important]复制代码

4 T  v6 \0 {/ r- d# s" I( V
, \2 d$ R0 J( m; `! t6 o# ^# J& x( y: e" T
关于楼主的步骤二的一个特殊解决方案:
6 Q4 @9 c- f1 _  x9 N- g  F  P打开
# ^( n% N1 U0 E; x  E7 [source/admincp/admincp_domain.php4 x/ G; i8 G% Z  B
删除或者注释此段代码
  •    if(!empty($domain) && in_array($domain, $_G['setting']['domain']['app'])) {
  •                                 cpmsg('setting_domain_repeat_error', '', 'error');
  •                         }; M2 W( I; q. O& V& ]( c$ H; b( r

" e- |! I' C% E0 f( a' @3 B5 j[color=rgb(51, 102, 153) !important]复制代码

  t' A( C) p# [1 o8 _' ^. h3 Z$ l# J8 E' f3 z
此修改是去除“配置中存在重复的域名”检测' Y' T6 T7 p. t$ m( I; m7 @
然后在后台——全局——域名设置
) r9 r1 N5 K1 a7 Z把首页和默认设置成同样的域名即可
; [" `1 F/ b$ U. K$ z. }3 C! t; `" Z此方法仅限于门户为首页时可去除 portal.php 包括导航栏中的 portal.php& @0 R5 M0 N0 k% [

+ ~: v. G- c- \$ a. e# C" x\template\模板文件夹\portal\. \: ?- z9 Z' }3 H

9 C* [# t) Q9 b: e1 _list_xxxx.htm (这对应频道文章列表页面中首页对应的链接)
! D- m; \! E# V& ?view_xxxxx.htm(这对应文章页面包屑中首页对应的链接)
! Y* q% T' Q' [! C5 F
$ l" L" D6 r) q* Y! o把所有在<a href=  也就是有关于输出链接里的! x7 m5 b& _4 v" Q, Z" R
  • {lang portal}: n  Y% S# p, C% N! z

4 Z8 H8 X8 E4 b; I[color=rgb(51, 102, 153) !important]复制代码
$ L4 Z, L- K( R' }
改为
) \& s  q9 i) }6 @/ Y2 k+ z5 W
  • ./
    . M# X; R9 q- K- c& \. Q) Q' Q* v
, x- W' c) u* ]: q" |/ |9 a2 }( e
[color=rgb(51, 102, 153) !important]复制代码
* ]. C" z& e+ `. F, {+ \7 X
即可3 E4 b! x; w+ y1 v

7 v" m5 Y, m; A! j* _) y' c后台更新缓冲即可解决!- g. e1 n8 r4 F! G
9#
发表于 2017-4-14 20:41 | 只看该作者
解决:; ~1 S5 z0 P. ~* d; b) k+ b" g) E/ A
<IfModule mod_headers.c>
  ]  {; c8 ]6 P1 v" S# I  Header set X-XSS-Protection "1; mode=block" 8 _; P. X1 c- J
</IfModule>: [% \. S( k: u0 r( c4 P) E

% w! q, y  e8 Khttps://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection
8 W  {- Z9 Q7 C& F3 S1 I6 R  W/ ^3 Z, A' x$ q2 S
<IfModule mod_headers.c>
' W+ v/ `2 H& K5 I4 _1 @  Header set X-XSS-Protection "0" : G" v2 C! s+ w: h& h9 \; J7 }
</IfModule>; F3 s% H) A) O9 b/ B
  l$ f$ c2 Q5 V' z
9 W. Y/ t( W" c/ b0 p) t* _
将博客文章推荐出现,chrome --X-XSS-Protection
10#
发表于 2017-4-14 20:43 | 只看该作者
This page isn’t working
* w; B3 E1 f+ k& c1 X" ]
! k1 G, ~: e" W1 i8 ~Chrome detected unusual code on this page and blocked it to protect your personal information (for example, passwords, phone numbers, and credit cards).
( `1 Q$ _  @" i6 VTry visiting the site's homepage.
6 ^9 |3 o$ u* Q& pERR_BLOCKED_BY_XSS_AUDITOR

使用高级回帖 (可批量传图、插入视频等)快速回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则   Ctrl + Enter 快速发布  

发帖时请遵守我国法律,网站会将有关你发帖内容、时间以及发帖IP地址等记录保留,只要接到合法请求,即会将信息提供给有关政府机构。
快速回复 返回顶部 返回列表