开启左侧

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

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

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

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

x
discuz X3.2在系统上是支持https的,不过需要手动修改几个地方。首先确保服务器端已开启https,且正确配置了SSL证书。
, b' o# P* Q' y5 y7 D& g
. f/ L; k+ l/ @/ s0 O/ s3 X  Adiscuz X3.2开启支持https主要需要修改一下几个地方:, Z' @8 h( b$ b% S, R

3 W: ^  @- y+ @. b7 v# K1、查找修改文件discuz_application.php :+ J' q' @- K/ k. J! s
source/class/discuz/discuz_application.php (约第 187 行处): 查找:" A' E( E7 T( w* f* W
$_G['isHTTPS'] = ($_SERVER['HTTPS'] && strtolower($_SERVER['HTTPS']) != 'off') ? true : false;+ l* d% C1 |% h/ k* F8 y
$ f5 u. k+ G) q4 O$ c- ^" z

% y( ^6 o8 F! F- s: h修改为:
1 T. J6 o. b0 P$ H7 O$_G['isHTTPS'] = ($_SERVER['SERVER_PORT'] == 443 || $_SERVER['HTTPS'] && strtolower($_SERVER['HTTPS']) != 'off') ? true : false;
9 ]! s9 W3 z. j. V5 p/ O! M& Q  l& g

5 x& j1 E7 `/ w% {$ c0 A" c; \2、查找修改文件avatar.php :4 I+ V2 F& I6 H! q+ e
uc_server/avatar.php (约第 13 行处)查找:
! x+ {0 g1 c/ d0 _; |! E
$ y$ T* h8 M! J/ K

1 j. G  X" @1 |2 gdefine('UC_API', strtolower(($_SERVER['HTTPS'] == 'on' ? 'https' : 'http').'://'.$_SERVER['HTTP_HOST'].substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'))));
. c# f) W+ R" h0 T+ }, Z- R8 C, c: Z9 s2 B! M, }" _( P7 b, _
. s" {3 k: O6 `! \4 D  `, ~' n

) A2 p! g9 @2 T* A( P
, S1 A" o) ?- X+ ?2 O: D0 y

5 q1 b2 E% \! E  Z3 Y! l: k" J修改为:
4 @$ l$ l/ u4 h1 X9 j# N% Sdefine('UC_API', strtolower(($_SERVER['SERVER_PORT'] == 443 || $_SERVER['HTTPS'] == 'on' ? 'https' : 'http').'://'.$_SERVER['HTTP_HOST'].substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'))));
; R3 {. T. q0 x
6 k# x8 g! i7 e. I0 }( K/ b

" _2 l( h& K) G- f7 c3、除去非 HTTPS 内容避免提示”不安全内容“
' c* J2 P6 w# J/ lSource/plugin/manyou/Service/DiscuzTips.php ,最后的那段 JS 加载脚本删除就行。: K! y) J% T& @  n4 W, R1 h6 J1 n( H9 E
非楼主层如果有点评,那么点评者头像不是 HTTPS 开头,也需要修改一个文件来适配: template/default/forum/viewthread_node_body.htm (约 180 行),搜索 div class="psta vm">,将下面一行注释掉或者删除。
: {0 F3 Y7 A1 |& J1 q/ R1 Z2 q: I打开浏览器,使用开发者工具或者查看源码逐一排查加载的非 HTTPS 资源并修改。
) E" X7 g# R) N7 e/ g" w' [& |: u1 J
3 ]7 {8 X/ k/ e/ H9 P5 p& V
4、后台设置的修改完善
. ^3 H& N, ^* ?/ ]在后台还有一些设置,可能会干扰 https 的使用。
  K& |- Z0 ]  a7 C! }: R

1 H1 R6 Z/ A" B, n( T后台 >全局 > 站点 URL ,改为 https 开头的

+ U  c% J+ m0 ?. Y5 X9 C4 W" A! `  O; x% i& o
后台 > 站长 > UCenter 设置 > UCenter 访问地址,修改为 https 开头的
% X' D* [& p- Y# ]" f) T8 H) s

2 R  V: Z2 H  {: c. TUCenter 后台 > 应用管理 > 应用的主 URL ,修改为 https 开头。

; H7 z0 r& W  ~& r1 i- f+ V修改后可能会显示通讯失败,如果 UC 和论坛程序安装在同一机器,此失败可无视,实测可以和 UC 正常通讯不影响(测试是否正常通讯程序的 Bug ),如果 UC 和论坛程序不在一台机器上,有可能不能通讯。 另外在 后台 > 全局 > 域名设置 中的一些设置也可能使 https 失效,如果更新缓存后论坛默认连接还是 HTTP ,请删除 后台 > 全局 > 域名设置 > 应用域名 > 默认 里面的默认域名(一般去 forum.php 尾巴这里会有内容,为了 HTTPS 请删除)。
- |7 y" [, [% y  q6 Z2 ^
$ Z9 e% j+ x; c3 m/ ?* y: O8 J5、模板的调整3 x- ]9 F9 E, p  X
主要在模板的 foot.html 以及 header.html 等文件中,使用工具逐一排查模板文件中写死的 HTTP 链接,修改为 HTTPS 。

' Y; g' p) k3 [2 ~; z& b. _
: `6 ]# ]' J0 \, P  \

6 u7 ?# @/ {, z6、数据库的调整
7 d, v% D' h' M; U在论坛这种交互社区中,经常回复发帖时会有出现主域名的链接,在没有 HTTPS 之前,链接都是 HTTP 开头,这个时候,我们需要修改数据库,运行下面的 mysql 命令更新数据库,将 HTTP 替换为 HTTPS :
& g4 ^3 h* u, O" b3 S进入 DZ 后台:站长 – 数据库 – 升级) |( p( h# m- s4 h# O
UPDATE pre_forum_post SET message=REPLACE(message,'http://你的网址','https://你的网址');
; P$ @* m3 i- s9 W0 V$ ?5 N& U2 C, O. y/ z" }  F
" Z$ v$ a- f& L) W8 ^/ e( i  O
6 @. l" V5 @& b$ @, X/ O6 X9 ~3 O: A
需要注意的是,出于安全考虑, Discuz 后台默认情况下禁止 SQL 语句直接执行,只能使用常用 SQL 当中的内容,如果想自己随意书写 SQL 升级语句,需要将程序文件 config/config_global.php 当中的$_config[admincp][runquery] 设置修改为 1 。) q% o1 p7 V3 d: |; U/ `; M
3 O1 v$ h, H$ J( d5 v# w5 r- m* m

) m! {" X) R3 k1 Z1 n0 K2 L到此,discuz X3.2已经开启支持https了 。
3 T* V# g, J6 ?# m4 R% h
" p1 g. R2 m  W, E& F9 s8 S
7 }+ R7 E2 i3 D7 B8 F! z
当然,你还需要申请SSL证书、在服务器端部署SSL证书。
6 c8 I, t7 A! p8 h9 t6 ^, n
% L& W% C" g. F& R, G! f" n6 q

2 A5 _% r$ s+ m6 R% e2 ]服务器端部署https的SSL证书可以看我的这个教程:$ c) D3 b% j+ E

- T$ B% D$ F$ q1 y, I$ p  h/ P: r+ r

( q6 ?$ F$ w# S) Xhttp://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'])
! K1 w. ]( E2 ]7 h- x! {: W: ^5 L$cssdata = !preg_match('/^http:\/\//i', $data['imgdir'])
4 d/ l2 O# H7 s" E0 s' M3 r$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');% ]+ t" P( B* r: M" {* k8 j
" ~$ s" R4 g. _
	if($step == 1) {
; M6 T3 y( M/ P# n6 y8 z/ n		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');
! U9 T2 E4 }! [0 s% a	echo '<br>';, A2 A! j# `; S* T5 m5 ^

0 f% A, M5 S% [* V3 P	if($step == 1) {
6 s+ t4 `- |7 y3 n9 u$ T, k		if($_G['siteurl'] == $_G['setting'][siteurl]) {
& H$ Q( z+ Y2 t7 a* X4 I7 `			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);
+ j6 K+ R( C$ E% R7 d( C' I4 X- a		} else {$ n2 |4 L) F- ~3 S4 n! 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') {( D8 O8 i; R5 v0 v! E
	if(!preg_match("/(Zidingyi|Bot|Crawl|Spider|slurp|sohu-search|lycos|robozilla)/i", $_SERVER['HTTP_USER_AGENT'])) {
! I2 q, D3 {& f2 i6 [( K9 b( l* O		header('HTTP/1.1 301 Moved Permanently');  @3 T' I4 U3 x8 h% _& e- N! H: z4 a
		header('Location: https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
& L; y$ t5 ~- Z7 m: i, T3 C" X		exit;8 A5 z! D& ?/ _( `2 _. c. t
	} elseif(preg_match("/(Baidu|Google)/i", $_SERVER['HTTP_USER_AGENT'])) {
4 E  c# B2 W7 P3 |8 w0 V- B5 _) j		header('HTTP/1.1 403 Forbidden');* B( f6 Q/ d4 F$ v5 W: a7 a2 x1 L
		exit;
) p4 }2 d, ?+ i4 C1 L. F( T0 G( w	}
- n: ?! R# B+ n$ G5 N% B) B: L& S7 [}

说明:当访问端口不为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:~ 
- B# ~2 I$ [1 d0 Q1 h

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 ssl
: @7 e- Z' o5 [) _5 \/ j  W; @) isudo service apache2 restart
8 j! y+ \( Z) ^% v7 ssudo mkdir -p /etc/apache2/ssl
" ~/ X6 i7 r2 G: t

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; s, z  d% S& I5 O. w
cp ~/{ca.pem,private.key,sub.class1.server.ca.pem,ssl.crt} /etc/apache2/ssl
- i6 }. l) R1 j3 |1 L) U

Execute:

ls /etc/apache2/ssl

And it should return:

ca.pem( X7 j9 \& ]! K
ssl.crt
0 W, G+ X/ j0 X9 e2 j2 r+ Eprivate.key
; V1 y- X3 \# B  i1 l7 q5 n9 ysub.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>5 a5 w' K- \: h9 R. Q
    ServerAdmin webmaster@localhost, S4 e. ?7 o3 c4 Y

0 U6 w5 O0 K; Z- g! v( M    DocumentRoot /var/www$ Z1 O9 [; ^9 X7 _/ E2 H
    <Directory />
$ x- x( s# C$ r2 `: e4 u  v+ q        Options FollowSymLinks
9 v# n( K. a' E/ F9 y        AllowOverride None  g! k! _; U* R( {* j6 G" P" i' t( v
    </Directory>
% Q7 h5 k" S) f/ t7 X- X    <Directory /var/www/>
0 y+ {3 ?# x. S        Options Indexes FollowSymLinks MultiViews, q& u* v3 W2 Y3 ?3 R" n1 k: q( U- N
        AllowOverride None
. d$ }4 H& m, F$ d        Order allow,deny
4 c. l9 m) e' x& }        allow from all
7 A, b9 @1 l  O    </Directory>
5 s  q& _7 b9 b: a$ |" R1 R- ~0 H. ?$ x( V$ `
    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
7 S7 M- c: r& L/ b" R/ k9 j) m    <Directory "/usr/lib/cgi-bin">
" j  t* M$ E% J# ?        AllowOverride None
" u5 T0 V  H1 G        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
6 L2 O3 C; Q& t6 f2 B( j7 v. o        Order allow,deny
; V+ R  Y' y+ G5 ~* [) z        Allow from all4 T, K/ p5 \5 ~' }
    </Directory>3 m& u: |6 l  d8 f
( E/ f- o0 _' ~! X, K4 j
    ErrorLog ${APACHE_LOG_DIR}/error.log
, r* y, d) i2 d8 ~1 w+ x
$ J% ~6 {# u, q) ?    # Possible values include: debug, info, notice, warn, error, crit,
3 U; T) P) _% r1 r6 S# e    # alert, emerg.
- j2 l# N$ g) Y( @7 P( Y    LogLevel warn
0 o; H, b5 g8 U6 T; O6 v
. c: {, x# Z) _# |' P3 P, {+ Z1 M* Z    CustomLog ${APACHE_LOG_DIR}/access.log combined
7 F* }( v( F9 f, B, ?
4 P  i" O# k: F    Alias /doc/ "/usr/share/doc/"
3 V7 u9 ~" y9 ?2 a: N* ~: t    <Directory "/usr/share/doc/">
* f/ g( N$ K: s- a# V7 r        Options Indexes MultiViews FollowSymLinks) ?6 D) y! {- h7 m( _8 E3 [5 M
        AllowOverride None
# l5 o/ [# P* [: {2 X        Order deny,allow
! g$ z! [. o" i+ V* _        Deny from all7 S) u. k2 M5 V' U
        Allow from 127.0.0.0/255.0.0.0 ::1/128
& }2 y2 T% ~5 Z; |; a( k7 K    </Directory>" E7 a6 M; n/ v' e7 ]& J

% I1 S( [* w" r( G4 n</VirtualHost>
. P9 K0 h  P' g9 E

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                                                                ) A, i& S8 G* r; u1 q% p
SSLProtocol all -SSLv2                                                      
) {- w/ m7 V$ A# i' _9 fSSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM                
1 e) T2 U+ j, E6 ~. g. G* ]% j7 d3 \
SSLCertificateFile /etc/apache2/ssl/ssl.crt                           
% S- W. I1 P- q: e7 ]SSLCertificateKeyFile /etc/apache2/ssl/private.key                        $ V) u: \# `; l% _4 [0 {
SSLCertificateChainFile /etc/apache2/ssl/sub.class1.server.ca.pem 

The end result should look like this:

<VirtualHost *:80>+ s0 V- [; m2 d) f& l' B- q
    ServerAdmin webmaster@localhost
: w8 [4 d0 `3 X7 n, E- {9 }* X" \0 ^# N' z
    DocumentRoot /var/www) f* W7 _( B% e! t! d
    <Directory />
3 I& X8 H+ M0 I0 N+ m  n        Options FollowSymLinks
# _3 \" A  j+ V! K7 F8 c        AllowOverride None
( ]0 p$ P3 n0 M  B    </Directory>
: T: k& E% G& @7 _7 Q    <Directory /var/www/>
8 x! K/ g5 o2 O3 h$ S, `( E! }# v        Options Indexes FollowSymLinks MultiViews
* J+ g- K* J+ [: K        AllowOverride None! i& j( f  v1 _+ B7 j
        Order allow,deny! ]9 H! H  c# j+ g  E
        allow from all2 e5 f4 ]* w( L- r) N
    </Directory>
6 [- z0 B6 m+ z  U3 y; p. h$ h: k0 d4 m% q
    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/6 m# O: l) p' M- |  Z0 |3 k
    <Directory "/usr/lib/cgi-bin">$ J  {8 s% \5 s  Z2 \, q& u- Y
        AllowOverride None& s0 e" w2 }5 T7 D$ O( \: b, k
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
( n" O7 f) H, u/ s, X        Order allow,deny, l9 L# |9 `* g; i( ?1 e% r: x
        Allow from all7 P/ G4 K- s  X  U- _3 o2 k) S; ~/ E
    </Directory>, T7 i3 A; h' |; k; T2 x; ^9 P

: J) M7 e7 @6 Q& l    ErrorLog ${APACHE_LOG_DIR}/error.log
7 w2 |- X2 G" G: s+ q" }3 ~: X& W7 O, F" E
    # Possible values include: debug, info, notice, warn, error, crit,
  k2 V1 N/ @- T    # alert, emerg.* e) p7 k9 ?" p2 g
    LogLevel warn/ l) f4 ^9 X: m  @

) }, E/ [: h0 w! j! Y    CustomLog ${APACHE_LOG_DIR}/access.log combined
' \2 e1 l1 B: C. I
: @. F" [7 R* s5 T0 A& O    Alias /doc/ "/usr/share/doc/"
/ r; c- K5 a. n1 l5 Z% ~    <Directory "/usr/share/doc/">; B4 t9 R3 B, I) ]2 u
        Options Indexes MultiViews FollowSymLinks
- B3 Z  Z# P$ P8 A, _        AllowOverride None/ E& d! s6 g4 N5 y7 x+ n
        Order deny,allow
3 u% m0 g8 }, y1 Y7 V; n( C        Deny from all
$ X9 K% l! _* ^2 S% t% g4 b, J        Allow from 127.0.0.0/255.0.0.0 ::1/128' v/ n& J3 z) s- P
    </Directory>
2 Y3 J9 _9 `. z# X: }8 k( `; Y- P5 y/ N* z  ?  N
</VirtualHost>; \" b, @9 z1 ~$ S" Y! J& ?( Y! d
. G; y. ]# U7 P" S
<VirtualHost *:443>! i6 e/ o, V5 S7 |( N
    SSLEngine on                                                                
5 A3 T  a( _# h1 X. l- T    SSLProtocol all -SSLv2                                                      
# C2 a/ y4 i2 y( l" T7 H    SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM                
2 X( p2 A+ ^$ x7 p% N
! [# |9 G2 Z8 k5 r0 t( ~    SSLCertificateFile /etc/apache2/ssl/ssl.crt                           
( o+ P/ l: J" U, b    SSLCertificateKeyFile /etc/apache2/ssl/private.key                        & X; O" R; Q( }7 R* {/ I0 a9 F
    SSLCertificateChainFile /etc/apache2/ssl/sub.class1.server.ca.pem " p& w# `- Q3 R( R
    ServerAdmin webmaster@localhost  ^% E9 c, q) \* f! T; i

( D3 s4 ^( O$ p" D- F    DocumentRoot /var/www, v' S' k7 ]# a3 d
    <Directory />
' w/ D7 B& g; b. h8 h" h: Q8 j% }        Options FollowSymLinks7 z6 Y/ a& p' U5 ]! q6 j1 a+ }8 v
        AllowOverride None
; v3 G! i; Z# ]3 f% @    </Directory>, F4 d( z/ R; g9 w; \! d; M
    <Directory /var/www/>
* R4 D2 T9 Z; U9 `        Options Indexes FollowSymLinks MultiViews6 b. c" i5 S: G" @8 O4 p
        AllowOverride None
1 Q' J, e1 O3 X) n" b* p6 T, L( v' E6 G        Order allow,deny
% o' i$ J# J; J" y3 P        allow from all
( U  u4 c8 K- E, u% b% l+ N    </Directory>
+ a/ t4 b# g$ z& }; r7 ^- E! |1 a5 M- Y( U5 ^. E
    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
' `1 P5 Y, g1 f    <Directory "/usr/lib/cgi-bin">" \8 J8 t7 s2 h) ^* m2 c
        AllowOverride None7 R; j) k$ }* D
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch( a/ a5 [- S" f( D
        Order allow,deny) b* \8 P2 g8 ~' B
        Allow from all5 S0 Z, o; [" W" {
    </Directory>
- L' l- i  ~1 [: n! Q! n9 m7 c, d5 J% Y3 Z$ N: o8 k. [
    ErrorLog ${APACHE_LOG_DIR}/error.log
+ A% l- S! t" t5 F
8 L8 M7 o& g& F3 c8 @  i7 v    # Possible values include: debug, info, notice, warn, error, crit,
9 t+ m& r2 u" H' A, }    # alert, emerg.
8 w, _1 v6 V7 ]    LogLevel warn
% N) g9 A6 e/ s$ m. T' g  X9 z3 ~+ M* M1 d0 l8 m
    CustomLog ${APACHE_LOG_DIR}/access.log combined* B! ]/ S- G! d' z  e: R- c8 A8 t

% r* A5 R' b' s: T4 c# m2 L6 o; S+ W    Alias /doc/ "/usr/share/doc/"# Z( F' l- r  _5 [9 A, t- Y! U5 W
    <Directory "/usr/share/doc/">
/ _2 t/ j# I1 ?/ x* Y6 o( V' Z* O        Options Indexes MultiViews FollowSymLinks9 {3 Y* p+ w3 r4 e0 c
        AllowOverride None
! j6 B  F$ d) X3 d- q, @        Order deny,allow, v% e& t5 h( L( K( P6 U
        Deny from all- a* x, S# s" i$ g% j6 Y6 A! u
        Allow from 127.0.0.0/255.0.0.0 ::1/128
  T: z2 }: Z) C  x* A5 K  l    </Directory>
* X- {4 x% a$ F/ t
, R: t' d# T0 L7 y3 w$ g  N: L( a' [</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.log0 Y/ c( k: c9 n0 w0 _

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-047 s, n+ N: F) Q

' h8 m# j8 W7 v9 z
4 q0 z/ X. H1 U- E2 S* ?: U& t- vIntroduction

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.


/ E$ y* P8 ~, F( pPrerequisites

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" N: X& D3 L+ d0 t

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

5 z$ U! _% ^/ Y
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' K* O) K! k' ?' \2 J+ I

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; g- j, y% Z, v4 c- j6 d! ^

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


" U5 O+ p+ ]9 ?$ d! ?" }Step 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. g' r/ j3 U6 o8 o, }% O

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
    ' a) e. i" a; u

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.


2 m7 B2 r* v) Z7 x7 W" q7 iStep 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' I* B) @* k- T- A% m3 [

Include the following content, all in one line:

[color=rgba(0, 0, 0, 0.298039)]crontab
, u9 U/ n9 M; f$ A30 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.

4 E' u' T5 F- a% w& g0 W$ s
0 y  K2 v' H$ @7 M7 n+ q% C
5#
发表于 2017-4-6 12:06 | 只看该作者
How To Use Cron To Automate Tasks On a VPS/ N; _$ I4 T- Z0 q8 z' D
https://www.digitalocean.com/community/tutorials/how-to-use-cron-to-automate-tasks-on-a-vps
! [2 w0 W7 O% P. [/ p
( L& }, I& a0 [Introduction

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.”


. ]( m4 x8 R# n; G) O2 mInstallation

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, }$ B3 k# L" ~( }! l
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
    - u! I: y7 I" G# G% u

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 week
    ' b8 c+ I6 T5 _2 p1 E' h
. F4 K/ a. z. r# Y) I5 _, G# p) x
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.


5 r1 _) b3 B  j: jConfiguration

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


7 y! p3 n$ v: I5 G* 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. q! w0 Y6 M% V5 I; ?8 T
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.

4 K9 v+ q( v( z6 x5 X! Y* p7 i7 x% p0 h
Special 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 *$ v' A+ r4 i2 [; x8 F

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.


, A& F7 w1 F) ]- V$ r. o
1 _) }) o8 z) I) W% S. _( y% A" I" M$ Z* i
6#
发表于 2017-4-6 12:10 | 只看该作者
https://debian-administration.org/article/349/Setting_up_an_SSL_server_with_Apache2
% C  P; O/ e$ A
3 V, d. U# v3 [# b% iSetting up an SSL server with Apache25 M7 z6 P4 S7 L6 v; {( T# G4 b0 Y  q, m; ?
( I0 D/ e$ I9 |; {3 j, e- h: W5 q$ f- e
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.
    4 ]# U6 U0 P& f9 y8 S) }
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>
8 W2 `4 m* I/ _* W8 J' O
7#
发表于 2017-4-6 12:12 | 只看该作者
Redirect HTTP to HTTPS automatically  L. T  l& m$ W2 w4 ?
https://ca.godaddy.com/help/redirect-http-to-https-automatically-88280 r* T6 p" B/ u) |

6 t6 E: W* `3 p# o
0 S- ~  k% h$ \( P& d6 r" O
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.
    / A2 X1 b6 d" E* [" |; F" k: V" B
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)2 ~+ ~) n; {9 D2 a
    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.

    ( B- F& F+ y1 @% }( r# d3 |
; F+ T) R  w8 R9 _$ W

: B, m% }# N/ g$ s7 H2 t
8#
发表于 2017-4-6 14:51 | 只看该作者
DISCUZ x3.2 开启301强制跳转https后 门户栏目出现302死循环) y4 U" `9 _" f# ^% v

& b. G6 o9 J' v9 E% u4 q+ O# p( A/ T+ ?3 P" _
自己测试figureed out:* m  C0 {0 T* R$ `2 z: i0 H4 P4 D
* B' i9 {, ^) b/ Q, n
1:全局---域名设置---应用域名---全部清除$ z# N3 d- H. k. ~! }: Y6 i8 |  E2 \
# ^* l- ^' }! H3 B% q
2:全局---域名设置----根域名设置---频道---留空9 \. L0 _( S0 Q/ ^. i/ C/ C& |. t3 x

9 f% T: f; t4 y! w+ r  I9 w+ f6 ]: Q" ~, }
也可参考:
, `1 P1 `6 u' ?) o+ H4 x9 P0 ~8 i$ W  B# ^4 l
DISCUZ x3.2 开启301强制跳转https后 门户栏目出现302死循环
7 ]% o& d# r  R( B% I
0 m! k2 x% e5 _* M5 K$ O% Ghttp://bbs.zhanzhang.baidu.com/thread-166634-1-1.html8 t/ j0 b5 u/ e2 k  B+ K1 N

4 o5 T' T0 _, m3 `) P
5 z3 G" Z7 r+ y+ ~$ B% ?8 P' o此方法并不能彻底解决此问题,正确解决方案:+ S6 D8 ?9 R  T* l# c$ a
, |5 u* l( o+ e( q
用最新版DiscuzX3.3的方法移植3.2上面即可解决
5 E% K/ s* I. W: b8 {打开
/ q" N2 d' |' T8 Z! Asource/function/cache/cache_portalcategory.php! S( P( ]$ ?/ l3 N) ]
查找3 t2 U3 H* F& w9 q5 I9 C
  • $portaldomain = 'http://'.$domain['app']['portal'].$_G['siteroot'];2 N. ~1 z' l2 k" K
4 _0 o. A/ [( v5 I' Q# x: Q# K
[color=rgb(51, 102, 153) !important]复制代码

  \' y: Z/ U8 `5 i, R- e替换为
4 ~7 f! w" f! I% S1 f& A
  • $portaldomain = $_G['scheme'].'://'.$domain['app']['portal'].$_G['siteroot'];
    - V/ O+ s$ O- X- @
7 u; w! x0 D7 F0 j( v  C$ f+ B8 c; i
[color=rgb(51, 102, 153) !important]复制代码
2 ^1 v, `% H9 s6 s* b0 R2 y

! U1 ?% ~. N  c6 k% V
' E. m# b8 B5 g9 `0 f查找! O2 z$ u0 U3 [# v( _* l( I
  • $portaldomain = 'http://'.$domain['app']['default'].$_G['siteroot'];
    - q: B- C. ]. a! z5 o; \9 h$ U

- J& ?3 c( s6 Z$ W: \[color=rgb(51, 102, 153) !important]复制代码
  T. l4 R+ l" `6 n- Y- ]
替换为8 b9 t0 E9 [4 p% o  ^, z
  • $portaldomain = $_G['scheme'].'://'.$domain['app']['default'].$_G['siteroot'];
    * P+ ^. n" h& V4 j3 N5 ^& \1 Y" c
* o# Y& D& m/ l4 w% q/ p
[color=rgb(51, 102, 153) !important]复制代码
3 K( J1 ?) F3 l: _/ _( t" A5 H. J
* C; `8 |6 P: A& K

; L4 R; Z4 |" g; D* h" `查找
) b4 a* v/ Y( t/ q
  • $url = 'http://'.$data[$topid]['domain'].'.'.$channelrootdomain.'/';
    6 ?1 y# F( z1 L) O, a# d

. n% F- O/ O! ^* @  ~. K[color=rgb(51, 102, 153) !important]复制代码
  @) l$ {4 @: \/ l
替换为/ r5 ~' T0 L- d
  • $url = $_G['scheme'].'://'.$data[$topid]['domain'].'.'.$channelrootdomain.'/';
    1 b+ ]5 c3 e/ M7 n! ^

# F0 F+ {) o/ R, p6 r3 v9 I& S[color=rgb(51, 102, 153) !important]复制代码

- f1 C( `6 K8 c' @
( e2 r' u* M8 _. O8 ~
" d/ H5 ?( {7 D7 ]8 t关于楼主的步骤二的一个特殊解决方案:  |3 H: y7 x' c8 G0 r
打开5 t8 c' m% k& |! W# O/ [
source/admincp/admincp_domain.php* h% P, z2 K8 {9 i# J
删除或者注释此段代码
  •    if(!empty($domain) && in_array($domain, $_G['setting']['domain']['app'])) {
  •                                 cpmsg('setting_domain_repeat_error', '', 'error');
  •                         }& n* ~9 l: E) y" |! l* z# h
( C& e4 k  S- K; j7 R( b
[color=rgb(51, 102, 153) !important]复制代码
( Z- z1 M! Z% Y& z: I
+ j. |+ G1 O* `6 @/ M+ i) [
此修改是去除“配置中存在重复的域名”检测
' L, p  O+ ^! T4 k% D; p然后在后台——全局——域名设置
1 q* Y8 R% W# u0 g3 B, `& k1 N把首页和默认设置成同样的域名即可
& T+ x7 l6 e1 a# t  t5 s此方法仅限于门户为首页时可去除 portal.php 包括导航栏中的 portal.php0 I( N/ s3 X& b% @4 \
; i6 N- \6 ]5 `$ H. x" L- W
\template\模板文件夹\portal\
, R( v* q, j! y- B  W$ c9 B! w' Z5 ?# X9 S& c- t4 i4 g) U7 R. y
list_xxxx.htm (这对应频道文章列表页面中首页对应的链接) 2 ~/ I; e& S: c& B
view_xxxxx.htm(这对应文章页面包屑中首页对应的链接)9 c/ H/ ?- I* E4 ]; Q$ f; ?
! T  v* u, Q. q5 D/ |( e6 z  A/ s
把所有在<a href=  也就是有关于输出链接里的1 u% m9 y1 n# b5 k
  • {lang portal}
    * I; J( G0 F& L! F0 \$ C, q
- m3 t3 ?8 o1 s9 `' Z4 M4 ?' e8 c
[color=rgb(51, 102, 153) !important]复制代码

, ~& j) p  T5 |0 ?! s改为
" x; N; a. O7 s0 Z
  • ./6 i' L3 U8 H9 _. d; F' B
  h1 j( v, T% [: o, d
[color=rgb(51, 102, 153) !important]复制代码
: N1 N# m+ m5 B5 [/ D1 Z. |7 b
即可
0 L% P# I* Q1 f( u; P1 U
6 M8 b* @9 _' [8 T; Q& B  X后台更新缓冲即可解决!% l$ @& l. I" C  [1 L
9#
发表于 2017-4-14 20:41 | 只看该作者
解决:
( w  s  ]% B5 J3 z# V<IfModule mod_headers.c> ! J/ `* `7 J) \( l! U& h) D- [5 J
  Header set X-XSS-Protection "1; mode=block" - h' w  q* F+ d+ @: Q- \
</IfModule>0 k3 k# ^2 F& t# q* Z! q( ?1 r$ [" H
' O, r$ @: k5 X
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection" o  c  ]# Q. F% y5 a, M4 {/ e
$ k: @! P9 b3 n, m
<IfModule mod_headers.c>
' c8 H1 K4 e# n; D  I  Header set X-XSS-Protection "0" ! q# @9 C$ q% L
</IfModule>
) L+ h  z- Y3 A: W6 G) \, y! ]
+ e, U% h! E0 O/ `
5 R( J& q$ l0 i5 p将博客文章推荐出现,chrome --X-XSS-Protection
10#
发表于 2017-4-14 20:43 | 只看该作者
This page isn’t working: u' R) e* M9 ?4 G* q) V. U

% n/ v/ X* t5 }* R. LChrome detected unusual code on this page and blocked it to protect your personal information (for example, passwords, phone numbers, and credit cards).. p, v0 k6 J7 G7 i- L3 w. r9 p
Try visiting the site's homepage.
5 _! F( d  _6 c8 q. ^ERR_BLOCKED_BY_XSS_AUDITOR

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

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

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

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