北美网备份站

标题: Discuz! X3.2 实现全站 HTTPS 终极教程 [ [打印本页]

作者: 北美生活网    时间: 2017-4-5 17:36
标题: Discuz! X3.2 实现全站 HTTPS 终极教程 [
discuz X3.2在系统上是支持https的,不过需要手动修改几个地方。首先确保服务器端已开启https,且正确配置了SSL证书。7 |  b! t  E3 X0 ]
7 N' O" [+ e. R9 K9 A8 M' D
discuz X3.2开启支持https主要需要修改一下几个地方:/ b0 A; i  _/ V- n+ f

2 \9 X; W6 A: v8 D! ?6 H3 N1、查找修改文件discuz_application.php :) [' [. R) r9 {- Z5 C  Q' }
source/class/discuz/discuz_application.php (约第 187 行处): 查找:! |5 P/ ]( M* O4 c, p- }- _
$_G['isHTTPS'] = ($_SERVER['HTTPS'] && strtolower($_SERVER['HTTPS']) != 'off') ? true : false;9 s: u1 T( O0 I

0 e$ N4 I, W; c7 r; z9 q$ O
' C: I4 I% h3 s$ t$ d修改为:
; o4 {1 e7 u( g' A- N! i) R3 h- @$_G['isHTTPS'] = ($_SERVER['SERVER_PORT'] == 443 || $_SERVER['HTTPS'] && strtolower($_SERVER['HTTPS']) != 'off') ? true : false;# x4 P9 b9 n' z9 f( d/ V

# ^# i( Z( T" [# P1 v1 T# Y% U. F+ T# y5 ?. Y/ }
2、查找修改文件avatar.php :/ `3 K  O% |% l. N( X/ T
uc_server/avatar.php (约第 13 行处)查找:
% i- K3 B4 Y% b+ [
& a* h" A0 ~* D# @0 @

7 B" D: {# Z# Hdefine('UC_API', strtolower(($_SERVER['HTTPS'] == 'on' ? 'https' : 'http').'://'.$_SERVER['HTTP_HOST'].substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'))));
( R, v3 d7 L6 t. S# {; W  w( ^, Y3 o0 y  q5 y! w6 m, O, i
  `; l2 R( L* v+ U' L4 E( \

# y" ?/ p! ~6 Q3 M- V: a6 F2 ~4 \; l

6 ]  A0 K( T* Y( {/ R+ d' A$ b修改为:
; k' [- Z, J) K6 Wdefine('UC_API', strtolower(($_SERVER['SERVER_PORT'] == 443 || $_SERVER['HTTPS'] == 'on' ? 'https' : 'http').'://'.$_SERVER['HTTP_HOST'].substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'))));
( K8 v" ?* A* p
3 x' b# [. S6 u  A) |' V

8 {, s3 ]6 T; V( @+ ^3、除去非 HTTPS 内容避免提示”不安全内容“
# g8 T* e1 T0 k% BSource/plugin/manyou/Service/DiscuzTips.php ,最后的那段 JS 加载脚本删除就行。/ C0 M) w  F9 N( u; T
非楼主层如果有点评,那么点评者头像不是 HTTPS 开头,也需要修改一个文件来适配: template/default/forum/viewthread_node_body.htm (约 180 行),搜索 div class="psta vm">,将下面一行注释掉或者删除。& a: j' l2 v- Q( F# w" B7 [. v
打开浏览器,使用开发者工具或者查看源码逐一排查加载的非 HTTPS 资源并修改。
6 J% D2 `; j) O) c8 `

) y. M4 a, N/ c* {& |4、后台设置的修改完善
& F- p! M. K$ }在后台还有一些设置,可能会干扰 https 的使用。
$ ^+ P& N* b3 T9 t* q

$ I0 D+ u* ]# d% Y后台 >全局 > 站点 URL ,改为 https 开头的
1 i6 o/ I8 c2 @( h# z8 _/ I) a
( J. Y( q* `( P
后台 > 站长 > UCenter 设置 > UCenter 访问地址,修改为 https 开头的
4 t% P* {7 c  B- n8 B: j4 W

# Y4 b* l9 N9 v& A# h6 kUCenter 后台 > 应用管理 > 应用的主 URL ,修改为 https 开头。
8 S) ^" A* z" _! W
修改后可能会显示通讯失败,如果 UC 和论坛程序安装在同一机器,此失败可无视,实测可以和 UC 正常通讯不影响(测试是否正常通讯程序的 Bug ),如果 UC 和论坛程序不在一台机器上,有可能不能通讯。 另外在 后台 > 全局 > 域名设置 中的一些设置也可能使 https 失效,如果更新缓存后论坛默认连接还是 HTTP ,请删除 后台 > 全局 > 域名设置 > 应用域名 > 默认 里面的默认域名(一般去 forum.php 尾巴这里会有内容,为了 HTTPS 请删除)。/ j5 U9 w& X2 E2 {% _
$ ^- w' d$ W/ q  _
5、模板的调整
. E9 C& e& P2 L( h. q主要在模板的 foot.html 以及 header.html 等文件中,使用工具逐一排查模板文件中写死的 HTTP 链接,修改为 HTTPS 。
2 K, D% C+ p) C2 v& B( A3 l8 [
/ n! x% u$ l: A" W
6 e! G7 d0 y8 z, A5 u
6、数据库的调整
# U# P- J+ K7 d' v: v- @* |1 M& y在论坛这种交互社区中,经常回复发帖时会有出现主域名的链接,在没有 HTTPS 之前,链接都是 HTTP 开头,这个时候,我们需要修改数据库,运行下面的 mysql 命令更新数据库,将 HTTP 替换为 HTTPS :
& N8 V8 C% J& z进入 DZ 后台:站长 – 数据库 – 升级
" u. B3 ~! _+ ]" w- t& O" T
UPDATE pre_forum_post SET message=REPLACE(message,'http://你的网址','https://你的网址');
$ j; [( [& n4 i. E9 y, |- s1 i! q: a' _
( Y5 ]' I5 O1 v  [) v% |& O, q0 e, H$ z; T' C1 J5 O

( r- ^' A/ K2 S+ w需要注意的是,出于安全考虑, Discuz 后台默认情况下禁止 SQL 语句直接执行,只能使用常用 SQL 当中的内容,如果想自己随意书写 SQL 升级语句,需要将程序文件 config/config_global.php 当中的$_config[admincp][runquery] 设置修改为 1 。2 a* d9 z$ G7 Q& x5 e3 [/ o) u

6 i5 h/ f5 w( G

! T, t. X3 {* i: C9 B) [$ u到此,discuz X3.2已经开启支持https了 。
* [$ l3 @9 e3 K) t" k' _! G+ C  q" M9 W

9 ]2 i+ O& E8 {* m8 @& u当然,你还需要申请SSL证书、在服务器端部署SSL证书。
, x' \/ g' ?8 S- b# a  y2 M
5 }/ N4 i8 @( y' n5 N* |$ a
4 o) C4 z- E; @& n# I0 ^- D7 s3 y
服务器端部署https的SSL证书可以看我的这个教程:
- w1 e5 p0 z: ?- {# a! Z! B2 R4 ~+ M0 a7 f
& V' D9 t3 h9 j  d9 A
http://www.aitiancheng.com/article-246.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'])9 p  _3 h, t- b4 c5 @
$cssdata = !preg_match('/^http:\/\//i', $data['imgdir'])0 g8 w6 Y8 v9 J, G" j- @
$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');
( v! b, @  a6 g
5 h  h! {8 H; r+ J2 e( c: |/ c% D7 L	if($step == 1) {5 v3 K* u  V' c0 Z
		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');; K( D) k1 f  b
	echo '<br>';+ U, x0 m" V+ `- j0 n0 u! l* o
5 y/ o- v. E* S3 K
	if($step == 1) {: M% p6 y; r6 D5 p1 ^3 v
		if($_G['siteurl'] == $_G['setting'][siteurl]) {) o9 E. p* m9 o  q* ^) |
			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);( @) Z" P+ K# V9 O9 h8 ^) r
		} else {
, i$ G# Y. V# F# C8 k			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') {7 K+ g/ y" K! D& l' F
	if(!preg_match("/(Zidingyi|Bot|Crawl|Spider|slurp|sohu-search|lycos|robozilla)/i", $_SERVER['HTTP_USER_AGENT'])) {
9 j9 x  n. Q$ K		header('HTTP/1.1 301 Moved Permanently');: _- ~' E8 q  C. q+ W
		header('Location: https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);+ J! k* V7 P0 I7 o0 y* X) J+ e% h7 Z
		exit;* K  d5 {5 ]0 J, {; _7 o) _1 b* N" Z
	} elseif(preg_match("/(Baidu|Google)/i", $_SERVER['HTTP_USER_AGENT'])) {
" }% N5 E6 p! }9 y! H( f: C		header('HTTP/1.1 403 Forbidden');
, A: k" D$ G. t& A) {		exit;6 p/ c1 v2 J; v+ U- D
	}. I7 l0 l" F" _3 Z6 D
}

说明:当访问端口不为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:

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:

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:~ , Y8 @& X1 R+ K' c

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
6 v* l3 S& q# qsudo service apache2 restart
, o& _" L* y/ g/ A/ y9 msudo mkdir -p /etc/apache2/ssl4 _0 l+ @( \; n- ]

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
  h: Y3 I. U) T7 W4 p% M! pcp ~/{ca.pem,private.key,sub.class1.server.ca.pem,ssl.crt} /etc/apache2/ssl
' c" u1 q1 f. R) N4 T: t9 E

Execute:

ls /etc/apache2/ssl

And it should return:

ca.pem9 |% w- n9 S+ ]: T  x3 k
ssl.crt" O& a; h/ i5 \; c: R" t2 K
private.key* [( ^- R+ f0 z/ h$ J  C0 e& ^# t1 C8 j
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>
9 X. t1 q6 M$ {4 q( s    ServerAdmin webmaster@localhost
' ~/ v! A! _4 q8 `
0 c) W- _6 }  V' G) M! a    DocumentRoot /var/www* @( D5 {! I3 d3 b6 @0 X7 \& r
    <Directory />
* k# v) k' Z! X8 v2 b! A' P        Options FollowSymLinks
  w( H7 d. ]* q: N* W) l        AllowOverride None/ c! ^- `# c; K
    </Directory>1 M/ Q# g, V- c2 r1 R
    <Directory /var/www/>; U6 }2 Y) }; u: i) j
        Options Indexes FollowSymLinks MultiViews9 y: u: H% _+ E# ~
        AllowOverride None
/ S4 j) u) h! U9 G5 D' s        Order allow,deny
7 W$ ?' V( u+ k# o5 A& o7 R        allow from all% D$ @; u) T% M2 z# h3 j, ~
    </Directory>
! w# p. K" x  s/ ?. p8 @$ X: ~% y
    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/+ e5 M- S- O6 H3 \
    <Directory "/usr/lib/cgi-bin">
, ^8 k% j0 W: V5 Y8 k        AllowOverride None) t, y% H6 f! t: h; V" u) _: v
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
5 H2 C: D8 y2 o% F        Order allow,deny
. E: R8 u& Y# o        Allow from all( h) w2 _8 }0 R+ r' a# t% [
    </Directory>8 B' W3 V4 n/ {' H

% S" ?7 e) m# ~    ErrorLog ${APACHE_LOG_DIR}/error.log
& \; I% Q. B. y! U3 k$ b% w! o# M* C. E+ A7 ?& S, f2 ]
    # Possible values include: debug, info, notice, warn, error, crit,
  S0 Q5 |5 V8 v" n3 G    # alert, emerg.4 N4 k6 o! ~% X% d4 u6 H
    LogLevel warn. Y) W3 n# z9 k1 T7 `1 u

2 b+ r7 b! h4 h9 W- i, ^+ V6 L, ]+ n    CustomLog ${APACHE_LOG_DIR}/access.log combined
. q. n) Y7 {5 f1 ]+ J; H7 d+ Z! m3 b# J3 x; m9 m; t5 i" W
    Alias /doc/ "/usr/share/doc/"
2 ^& V1 W, K* P8 P3 V4 s    <Directory "/usr/share/doc/">
0 s1 d7 l& b. D        Options Indexes MultiViews FollowSymLinks
* [# E' W+ p* ]+ k9 `6 j        AllowOverride None3 A3 e2 D/ ^* Z  p/ D
        Order deny,allow$ w2 v' m1 @. `& N" a
        Deny from all
. P) p3 n+ o# l7 A7 J        Allow from 127.0.0.0/255.0.0.0 ::1/128
; ^& m4 v' a: @    </Directory>
! w) ?" a, T! F- b/ N+ ?5 ~
: g9 T! n# R  M; n! N+ D</VirtualHost>) [) r9 i) X6 K9 J8 y% L& y6 q* c

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                                                                - n5 |; F/ X0 [5 ]6 ?  b
SSLProtocol all -SSLv2                                                      7 t% R0 ?. B1 m
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM                
' l2 n! z! C8 G& N/ E9 J* H4 Q8 \( K/ V; H' ?
SSLCertificateFile /etc/apache2/ssl/ssl.crt                           " Z& ^! v& d5 T0 P+ R
SSLCertificateKeyFile /etc/apache2/ssl/private.key                        : Q" ^2 H7 F4 B4 |
SSLCertificateChainFile /etc/apache2/ssl/sub.class1.server.ca.pem 

The end result should look like this:

<VirtualHost *:80>% H& W/ S( R/ ]9 Y2 P8 E# x. |
    ServerAdmin webmaster@localhost8 s( K9 D! q7 E, c

+ H5 a4 F, n* j0 ?, r7 x9 X    DocumentRoot /var/www
0 d% Q+ @; C9 ?/ i    <Directory />2 q' i* v4 A% V( d) ^4 ^
        Options FollowSymLinks$ l' I+ H' ?: }! Y6 Z
        AllowOverride None
3 h6 x& U9 ^) _/ L9 ?0 Q3 w    </Directory>
  O! A, f' C  o; z& C    <Directory /var/www/>3 Q' G7 x, D) A' g+ q- c2 t
        Options Indexes FollowSymLinks MultiViews" ]* }% I( r3 |" \5 _* @( k1 J" l
        AllowOverride None) i2 i0 Z* x5 n$ U% v  k) K- f# v
        Order allow,deny
; c4 D. K: `8 C) [- u1 _        allow from all/ B; _9 b- E" R, v1 i1 c; X2 F( z8 W
    </Directory>
2 N# X$ P) f8 k6 A# g% s
- e# Y8 d( h1 y" x! _    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
  i1 y' W0 E4 B    <Directory "/usr/lib/cgi-bin">
9 j% ?( C% b  e4 }1 a        AllowOverride None0 C) Y5 B: z" W8 l4 W" g+ O7 r
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
/ O2 ]/ k0 A4 m  C3 `        Order allow,deny
8 E% E. c" h# \' t$ ]2 ^        Allow from all4 u! a2 V# d0 Y8 ~" j5 }8 M2 n
    </Directory>3 _- W& {, r" d0 n( r

  \3 k- [; N1 j* Y6 g! I    ErrorLog ${APACHE_LOG_DIR}/error.log
8 W+ G+ y6 Q: N# F( ~, T$ q, L1 |7 l8 J* Y0 |, d' F
    # Possible values include: debug, info, notice, warn, error, crit,
2 U! ~, j- p, U% @5 M$ V    # alert, emerg.
* F5 z1 J$ J5 a; W    LogLevel warn9 A1 |1 H# N. m- F$ q

! g, `, J4 ~+ f( ?# {    CustomLog ${APACHE_LOG_DIR}/access.log combined& m: U/ i7 i! f, l+ Q- t
/ A/ x9 w2 r$ o- o3 V4 ^( \
    Alias /doc/ "/usr/share/doc/"
- F3 p  E+ F5 ~) i    <Directory "/usr/share/doc/">' y! c5 Y% b% G& X$ {& k6 ?, R: j" t
        Options Indexes MultiViews FollowSymLinks* w+ _2 p% ^  d. g0 o& L
        AllowOverride None
; ]+ B2 h4 ~/ v3 n5 M( h6 T        Order deny,allow
  o5 O9 W/ d+ P% _: E6 b        Deny from all, n3 j, x: [& E) ?: k
        Allow from 127.0.0.0/255.0.0.0 ::1/128/ C2 A6 k0 F# k5 T4 F
    </Directory>7 I  v  q) r! o' v2 D

: d, m4 ?1 {7 _2 W3 B</VirtualHost>; m7 |/ ~* K# v5 y- @0 Z
/ b3 T* Z3 U  n9 G" o
<VirtualHost *:443>
( E8 z$ ]5 A3 G9 P  }3 F# d    SSLEngine on                                                                
3 K* P+ }3 Z0 ~( Q, I! m' D5 m    SSLProtocol all -SSLv2                                                      
8 a; K& ?5 o- Z" l- X    SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM                ' U& s5 I/ Q3 x: }) @+ }+ x

3 t9 [# C- c; G0 A5 P& \  m( W2 k    SSLCertificateFile /etc/apache2/ssl/ssl.crt                           : v+ J  T& O+ w3 k- Q
    SSLCertificateKeyFile /etc/apache2/ssl/private.key                        
3 E8 O& @9 Q) i% t    SSLCertificateChainFile /etc/apache2/ssl/sub.class1.server.ca.pem # w9 t! Z* N, _* }' G
    ServerAdmin webmaster@localhost
/ t, ?0 ]& N' h# A
, X0 \/ n) V. \5 T! s3 Q    DocumentRoot /var/www
" n/ J: s& A" ~    <Directory />" U6 F8 m2 T7 n8 s
        Options FollowSymLinks6 Y4 g; J; D' O- z7 [6 B% v
        AllowOverride None
+ d' l- {2 e& w1 [/ N" O+ h. U7 u    </Directory>$ V  P( H" p  t; q8 Q8 @
    <Directory /var/www/>- H( l; N/ x/ B- a0 q
        Options Indexes FollowSymLinks MultiViews+ d7 t7 n8 {- m/ A- h
        AllowOverride None5 ?: G7 Y% i9 w2 H
        Order allow,deny
0 Q0 x6 ^! j4 H) ^" i        allow from all, G6 v- L0 p  c
    </Directory>4 z* @: W$ A' a5 p9 P

" ]# V' M7 |- `8 t  M    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/6 w7 I" L' H. K6 ^' `$ A
    <Directory "/usr/lib/cgi-bin">( D% t0 c" |/ E1 m2 E5 e6 t
        AllowOverride None
; c; i8 S5 |! Y% r        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
% ?6 E5 E6 L5 V9 z/ `        Order allow,deny
$ r. K0 U0 ?5 W        Allow from all9 ^2 M' M8 P1 Z& Q
    </Directory>
& Q3 J& z# z2 j* a
7 p1 o, U- v( v9 e    ErrorLog ${APACHE_LOG_DIR}/error.log
! A8 m" _" Q$ o4 U
; N: K6 z& ^% W3 n+ o4 h  s1 g3 `+ y" V    # Possible values include: debug, info, notice, warn, error, crit,
. T; `( ]$ c2 z    # alert, emerg.3 d7 s1 T9 A1 t8 P
    LogLevel warn
4 `+ z8 f- u6 N! f
3 ], e6 \8 F" x7 v* K2 X    CustomLog ${APACHE_LOG_DIR}/access.log combined
6 q2 i1 _  U/ F; E6 U" w% K
  u2 @+ I3 t6 i/ r, J' b' k, _    Alias /doc/ "/usr/share/doc/"' \9 j2 F5 p# f: ^& ~
    <Directory "/usr/share/doc/">& X, ^" \  ?6 F( q3 C" b& \
        Options Indexes MultiViews FollowSymLinks! Q1 K: o9 Y, X. h
        AllowOverride None( z3 l3 g! \$ s9 A9 n3 Q
        Order deny,allow
* v* L! E, g% p& D0 e        Deny from all% c- M5 C8 J+ s/ u; G  Z
        Allow from 127.0.0.0/255.0.0.0 ::1/128
5 D3 `$ k9 X( `# k7 B    </Directory>
. K. Z: u* y* j; Y
9 F3 `( r6 w1 q4 c& r4 z</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
+ O0 J/ e% h% _7 u2 G

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
& Y, u) l8 q8 S
- E# ]6 `5 |7 L9 B+ i
- _4 ]$ w7 M) S- V2 {8 {Introduction

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.


4 U; r* S$ I& H- f4 ^7 U) uPrerequisites

In order to complete this guide, you will need:

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


3 a: h2 O2 P) pStep 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:

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

Make the script executable by typing:

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


& y! d6 A* T& h  A: iStep 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:

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:

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.


& u- Y: B5 L9 g3 l/ Y+ L: \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:

Include the following content, all in one line:

[color=rgba(0, 0, 0, 0.298039)]crontab
$ _' V" d5 S4 a. W1 r. J30 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 B# B! B0 `& D: J5 K2 E/ U
5 {% [3 @1 a; P' \7 Z" a8 l
作者: 北美生活网    时间: 2017-4-6 12:06
How To Use Cron To Automate Tasks On a VPS/ Z6 x( r( u$ R- @& `- p$ `# c
https://www.digitalocean.com/community/tutorials/how-to-use-cron-to-automate-tasks-on-a-vps% f* T8 o. P, X4 H  e

. \; e8 W" D8 Y  |& pIntroduction

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

  ~* f0 ?/ m+ _3 W! h1 w& _
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* L4 R  J: Z6 d% m5 p
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:

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:


; s7 t8 y; a1 a* [2 p' M, WExamples

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.

7 J' g  ]- I, x1 @( Z
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


# |2 B, h$ S* G/ c* f( O4 _Output

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/ N+ K, Q3 z! P5 B. O) K' W, }' u
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.


% |. T: m4 o$ l; e9 BSpecial 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:

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.

. w! D. Q7 |( |8 r' A3 s9 }

5 @& _) d+ ?' v* D
作者: 北美生活网    时间: 2017-4-6 12:10
https://debian-administration.org/article/349/Setting_up_an_SSL_server_with_Apache2+ \9 ?' D' z5 V: h+ U$ D0 ~

$ l% m2 `! O$ pSetting up an SSL server with Apache2% a) f; J, G& M7 f7 F- q
* j7 I0 P: ^; t2 g: G3 Y* f
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:
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>* ]0 A% x; X2 W

作者: 北美生活网    时间: 2017-4-6 12:12
Redirect HTTP to HTTPS automatically3 q$ y% k! l* Y& V" f! h, C! G
https://ca.godaddy.com/help/redirect-http-to-https-automatically-88285 K0 d& F, U! C- v/ ~; O

5 H: y/ {5 f9 R5 v/ g6 p
% |# C* O" M4 }' s
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:
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:
2 P7 T- E# {  ~, }  q
; c. B) i0 t& t

作者: admin    时间: 2017-4-6 14:51
DISCUZ x3.2 开启301强制跳转https后 门户栏目出现302死循环7 V' S  T" C9 O5 _
0 }2 v! A( G: i2 Z* C$ x
* a' u' V# T, O* J. `
自己测试figureed out:% S7 \* z! e4 d0 d- u- j5 C
" @8 b) {6 t) v0 E6 o/ V! Y
1:全局---域名设置---应用域名---全部清除
. o9 W1 P$ n6 z
4 y' ^8 w& R$ l- t3 [8 _1 C- E2:全局---域名设置----根域名设置---频道---留空
% h$ T& t. P$ S) F3 s3 ~* m& b! ?/ m+ t' s# V
6 s! k9 Z6 Z* M1 ^: t* H. c
也可参考:
6 m1 v: B/ l1 Q9 L
* }; G- d; V5 \$ J* VDISCUZ x3.2 开启301强制跳转https后 门户栏目出现302死循环
7 I& W  X2 K4 w, A* w" ?. n, E' T' o
' P. C% E+ O/ Q4 ?  ihttp://bbs.zhanzhang.baidu.com/thread-166634-1-1.html
8 Y! u7 i* X3 K' l& r0 H
1 v) l4 b& q2 G, v3 m" j* p* {- c" t7 I: P2 X* o- Y1 h
此方法并不能彻底解决此问题,正确解决方案:: h! h6 I& h8 q+ h, [. p
8 f+ f9 f1 o4 F- F% m
用最新版DiscuzX3.3的方法移植3.2上面即可解决
* R+ b5 b- v- u打开
& p$ p" S+ h% U* q& A" `( bsource/function/cache/cache_portalcategory.php
# s& Z6 u3 m; v" m# P/ P8 ~查找
4 Q# L4 I9 f4 E# h6 |1 M
  • $portaldomain = 'http://'.$domain['app']['portal'].$_G['siteroot'];9 r& R) T5 ]0 J: U/ n

. t# I  W% Z0 a( Y. i3 s7 }% v( [[color=rgb(51, 102, 153) !important]复制代码
8 M% u8 h9 T* m2 e$ R
替换为! y; \7 k% l7 N7 Y) R) G
  • $portaldomain = $_G['scheme'].'://'.$domain['app']['portal'].$_G['siteroot'];! h' }2 u% `4 H; C
; t) e  Q( p$ {5 o4 m! N+ d
[color=rgb(51, 102, 153) !important]复制代码
% z( t. }, ~7 p+ v; T

! }1 A3 a: y) j9 R. H/ e4 f( W0 J5 ~! a7 m$ M0 W5 G0 I$ k
查找
# c* G# _  ~! d+ Y% r4 J: z, T- ?
  • $portaldomain = 'http://'.$domain['app']['default'].$_G['siteroot'];
    + L8 @/ s4 q* s  _
5 k) ]4 m' @, Z: F! X2 |: j
[color=rgb(51, 102, 153) !important]复制代码

( l* {, I" S; K替换为
( ?& Y: `  `+ l* u/ f  H
  • $portaldomain = $_G['scheme'].'://'.$domain['app']['default'].$_G['siteroot'];
    ! A" Z! B3 u% h; L6 Q+ b" f, ]; l
4 D% B. x: d' n$ |1 G
[color=rgb(51, 102, 153) !important]复制代码
+ X! {7 f# O' B. p; n1 T4 E6 B: R

9 S1 ^7 ~7 N& n5 {5 i4 p: s
/ T+ U$ C% T, R9 w* T2 H查找
/ x2 I. ^) R0 Z3 I: w
  • $url = 'http://'.$data[$topid]['domain'].'.'.$channelrootdomain.'/';
    5 T$ m6 H7 c4 t* z) v. z  j. E9 h
5 P8 |3 t9 {. a; `# O$ N( a
[color=rgb(51, 102, 153) !important]复制代码

6 P1 Z+ J4 |% a5 `- q# Q  W! C1 I替换为! i, b; e' _+ H! n9 S" x1 t( H. o* e
  • $url = $_G['scheme'].'://'.$data[$topid]['domain'].'.'.$channelrootdomain.'/';" P; M  O8 V- Q3 j8 c: z7 [

* d6 n+ }0 J  F& \8 P+ k9 U* q[color=rgb(51, 102, 153) !important]复制代码

( i, Y0 _5 P/ m: z& P# U6 u, f. P7 z% o# O7 U7 }' X- }* L! O
" W0 S4 l& O. z, @4 o
关于楼主的步骤二的一个特殊解决方案:
* }$ z! ~5 m1 i& m- q打开
" K# h6 w" o, Q5 y2 esource/admincp/admincp_domain.php
* a; V' u2 K" B  c- M) I$ ?# [删除或者注释此段代码
  •    if(!empty($domain) && in_array($domain, $_G['setting']['domain']['app'])) {
  •                                 cpmsg('setting_domain_repeat_error', '', 'error');
  •                         }4 S- E, F" O; U5 z% x2 U4 R
* s8 k& \7 I: z9 b
[color=rgb(51, 102, 153) !important]复制代码

) g  r& H) n5 Y5 G6 z! {* Y* ~
* u+ W& E1 \( D4 \此修改是去除“配置中存在重复的域名”检测  q7 |0 h5 M. u* z& C
然后在后台——全局——域名设置
) _7 _' Q# _; b* T& v+ j把首页和默认设置成同样的域名即可
2 m% K; {" I" `, z$ R- X此方法仅限于门户为首页时可去除 portal.php 包括导航栏中的 portal.php- t7 y/ Q) ?9 e- I8 S

% x9 X2 L0 N6 r& b, g# v$ i\template\模板文件夹\portal\
4 `+ v) Q! ?9 U& Q% M# [# L$ Q
$ i  c5 r6 p9 hlist_xxxx.htm (这对应频道文章列表页面中首页对应的链接)
" A% Z1 e; R# ^6 Jview_xxxxx.htm(这对应文章页面包屑中首页对应的链接)' {" C( D2 D; H" I6 e/ X( i
2 W8 l4 ?6 e6 K$ Q* n( o. V2 M
把所有在<a href=  也就是有关于输出链接里的3 U9 P; E' x) J9 z1 G$ a
  • {lang portal}) T  R% q6 [: U& Y( n

, F# s6 |& f- \[color=rgb(51, 102, 153) !important]复制代码

9 D; g7 p9 s: r改为
4 L" k9 I1 W7 G& h- U/ l* z6 ^; @
  • ./
    * k' Y% {$ A" X: m
1 c: D) i+ O- G+ \
[color=rgb(51, 102, 153) !important]复制代码

1 ?" s  y# N, q& Q2 x2 V即可
2 J7 f1 F; ]6 S4 P
- h( r" @* ~- o9 C0 p2 i0 }: Z% x后台更新缓冲即可解决!
$ Y5 P5 a% @( x$ J3 J5 K# H6 t: d
作者: 北美生活网    时间: 2017-4-14 20:41
解决:
* G" x* Z5 w4 `% p<IfModule mod_headers.c> 0 a6 K+ a* A+ z
  Header set X-XSS-Protection "1; mode=block"
! T' t+ p; y, [/ u- g3 h6 v, D</IfModule>
. ?5 D5 s# O" o8 o: A
4 n* h2 a+ [) c6 A/ Ohttps://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection( d6 i  ?4 O( @. o# o6 `

- r7 H$ t/ W. K; v) @. f<IfModule mod_headers.c>
1 F# Q& F$ T& b0 A1 A& S, H  Header set X-XSS-Protection "0"
+ ~& x1 c$ d! u# h6 J2 P+ g</IfModule>
, S0 s, f/ D- }; l& R; }# D  n% [5 _" j
. v. t4 `) c8 A
将博客文章推荐出现,chrome --X-XSS-Protection
作者: 北美生活网    时间: 2017-4-14 20:43
This page isn’t working- j" P; a( j: q( U2 m) I

/ j3 h3 h$ h# f* |5 Y( GChrome detected unusual code on this page and blocked it to protect your personal information (for example, passwords, phone numbers, and credit cards).2 S: q" @9 E" |9 J
Try visiting the site's homepage.- j9 H6 |  X2 G' @  \: w& L' [1 g
ERR_BLOCKED_BY_XSS_AUDITOR
作者: 北美生活网    时间: 2017-4-14 20:43
Discuz!X3.1-X3.2后台admin.php防止直接恶意访问* N( a" K. M- F5 |8 J( w3 r& d

. }  O0 }( y# x8 c各位站长应该都知道Discuz!程序的后台是“域名/admin.php”,在站长朋友没有设置任何保护措施的情况下,任何人、任何一台终端都可以随意的访问到在php虚拟主机上运行的Discuz的后台,那么黑网站的第一步就不费吹灰之力的完成了,这里给大家分享一下如何防止Discuz!X3.1-x3.2后台被恶意访问,为了防止程序后台被恶意访问,大家可以做一下修改:
, Z$ |7 T% _  w5 Y1 @9 y. N! e在网站根目录找到admin.php,找到如下代码:
' q0 m9 \4 B$ ^  i  y+ P$discuz->init();* W3 W  j  d0 P6 o- o
接下来在此行代码下面添加如下代码:
! n2 R% @3 F; E" l. U6 H7 ?; xif(!$_G['uid'] || !getstatus($_G['member']['allowadmincp'], 1)) {
  x) M8 v- i+ f- gheader('Location: /');
; y1 o7 Z2 s8 C8 o$ ]+ L! b1 @}
" ^; z+ @  a# y9 m& t8 S9 z保存上传覆盖就搞定。这样就实现了非管理员全部返回网站根目录。, |$ _8 m7 L1 b6 U& M
如果管理员要登陆后台,直接在前台会员登陆界面登录就行了!




欢迎光临 北美网备份站 (http://beimeilife.duckdns.org/) Powered by Discuz! X3.2