SSL证书卸载与SSI高级应用

SSL证书卸载与SSI高级应用

http://netkiller.github.io/journal/ssi.html

Mr. Neo Chen (netkiller), 陈景峰(BG7NYT)

中国广东省深圳市龙华新区民治街道溪山美地
518131
+86 13113668890
+86 755 29812080
<[email protected]>

版权 © 2014 http://netkiller.github.io

版权声明

转载请与作者联系,转载时请务必标明文章原始出处和作者信息及本声明。

文档出处:
http://netkiller.github.io
http://netkiller.sourceforge.net

2014-09-17

摘要

我的系列文档

Netkiller Architect 手札 Netkiller Developer 手札 Netkiller PHP 手札 Netkiller Python 手札 Netkiller Testing 手札 Netkiller Cryptography 手札
Netkiller Linux 手札 Netkiller Debian 手札 Netkiller CentOS 手札 Netkiller FreeBSD 手札 Netkiller Shell 手札 Netkiller Security 手札
Netkiller Web 手札 Netkiller Monitoring 手札 Netkiller Storage 手札 Netkiller Mail 手札 Netkiller Docbook 手札 Netkiller Version 手札
Netkiller Database 手札 Netkiller PostgreSQL 手札 Netkiller MySQL 手札 Netkiller NoSQL 手札 Netkiller LDAP 手札 Netkiller Network 手札
Netkiller Cisco IOS 手札 Netkiller H3C 手札 Netkiller Multimedia 手札 Netkiller Perl 手札 Netkiller Amateur Radio 手札 Netkiller DevOps 手札


目录

1. 什么是SSI(Server Side Include)

SSI是服务器端页面包含,SSI工作在web服务器上,web服务器可以在一个页面中包含另一个页面,在用户端看来是只有一个页面。

2. 为什么使用SSI

我们又很多个子站,所有网站的header与footer都相同,还有一些block区块也存在共用。所以我们将这个共用的部分拆分,然后使用SSI按需包含。

3. 谁来负责SSI制作

稍有经验的美工人员都可以灵活使用SSI,程序员也可在短时间内学会SSI.

4. 怎么处理SSI包含

4.1. SSI 目录规划

/www/example.com
  |-- inc.example.com
  |-- www.example.com
  |-- images.example.com
  |-- acc.example.com

inc.example.com 是SSI共用文件,存放shtml文件。

www.example.com 是主站,会用到inc.example.com中的公共模块。

acc.example.com 与 www.example.com 类似。

注意

/www/inc.example.com是公共目录,不需要配置nginx,不能通过浏览器访问到该目录.

为什么要独立公共文件,而不是放在/www/www.example.com目录下面呢?我是为了方便发布代码,分开的好处是我可以针对inc.example.com做发布,而不影响其他项目。


由于include作用于web服务器的$document_root目录,例如当前$document_root是/www/example.com/www.example.com

<!--#include file="/example.shtml"--> 会引用 /www/example.com/www.example.com/example.shtml 文件,而不是操作系统根目录。

所以我们无法引用与www.example.com同级别的inc.example.com公共文件。例如:

<!--#include file="/www/example.com/inc.example.com/example.shtml"--> 会引用 /www/example.com/www.example.com/www/example.com/inc.example.com/example.shtml 文件,而不是操作系统根目录。
<!--#include file="../inc.example.com/example.shtml"--> 会引用 也无法正常工作。

这是服务器限制,如果SSI可能包含$document_root之外的文件,将会带来安全问题,例如

<!--#include file="/etc/passwd"-->

怎样能突破限制呢?我想出了别名,通过别名/include引用/www/example.com/inc.example.com目录中的公文模块,例如:

location /include/ {
        root   /www/example.com/inc.example.com;
    }

提示

Apache 与 Nginx 服务器的 SSI 实现稍有不同include file与include virtual也有差异。

4.2. www.example.com 静态内容服务器

# cat /etc/nginx/conf.d/www.example.com.conf

server {
    listen       80;
    server_name  www.example.com;

    charset utf-8;
    access_log  /var/log/nginx/www.example.com.access.log;
    error_log	/var/log/nginx/www.example.com.error.log;

    location / {
        root   /www/example.com/www.example.com;
        index  index.html;
    }

    location /include/ {
        root   /www/example.com/inc.example.com;
    }
    location /info/ {
	proxy_pass http://info.example.com/;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

4.3. acc.example.com 动态网页服务器

server {
    listen       80;
    server_name  acc.example.com;
    charset utf-8;
    access_log  /var/log/nginx/acc.example.com.access.log;
    error_log	/var/log/nginx/acc.example.com.error.log;

    set $X_FORWARDED_FOR $http_x_forwarded_for;

    location / {
        root   /www/example.com/acc.example.com/htdocs;
        index  index.php;

        try_files $uri $uri/ /index.php?/$request_uri;
    }

    location /include/ {
        root   /www/example.com/inc.example.com;
    }

    location ^~ /images/ {
        rewrite /images/(.+)$ /$1 break;
        proxy_pass http://images.example.com;
        break;
    }
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /www/example.com/acc.example.com/htdocs/$fastcgi_script_name;
        include        fastcgi_params;
	fastcgi_param  DOCUMENT_ROOT /www/example.com/acc.example.com/htdocs;
    }
}

注意

该服务器不对外提供服务器,只允许下面的SSL卸载服务器通过反向代理连接

4.4. SSL卸载服务器

将SSL证书处理,机密与解密操作转移到该服务器,不让业务服务器处理证书的加密与解密操作,上面的HTTP对内访问,HTTPS对外访问,HTTPS通过反向代理连接HTTP服务器实现SSL证书卸载

upstream acc.example.com {
    server acc1.example.com;
    server acc2.example.com;
    server acc3.example.com;
}

server {
    listen       443;
    server_name  acc.example.com;

    ssl                  on;
    ssl_certificate      /etc/nginx/example.com/acc.example.com.pem;
    ssl_certificate_key  /etc/nginx/example.com/acc.example.com.key;

    ssl_session_timeout  5m;

    ssl_protocols  SSLv2 SSLv3 TLSv1;
    ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers   on;

    location / {
	proxy_pass http://acc.example.com;
	proxy_http_version 1.1;
	proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        break;
    }
}

4.5. /www/inc.example.com 公共包含文件

/www/inc.example.com/include/cn/config.html

<!--#set var="HTML_HOST" value="http://www.example.com"-->
<!--#set var="INFO_HOST" value="http://info.example.com"-->
<!--#set var="NEWS_HOST" value="http://news.example.com"-->
<!--#set var="IMG_HOST" value="http://images.example.com"-->
<!--#set var="JS_HOST" value="http://images.example.com"-->
<!--#set var="CSS_HOST" value="http://images.example.com"-->

<!--#if expr="${X_FORWARDED_FOR}"-->

<!--#set var="ACC_HOST" value="https://myid.example.com"-->
<!--#set var="IMG_HOST" value="/images"-->
<!--#set var="JS_HOST" value="/images"-->
<!--#set var="CSS_HOST" value="/images"-->

<!--#else -->

<!--#set var="ACC_HOST" value="http://myid.example.com"-->
<!--#set var="IMG_HOST" value="http://images.example.com"-->
<!--#set var="JS_HOST" value="http://images.example.com"-->
<!--#set var="CSS_HOST" value="http://images.example.com"-->

<!--#endif -->

${X_FORWARDED_FOR} 用来判断用户是通过http还是https进入,由于images.example.com 没有SSL证书,需要有区分的载入图片的地址。/images 通过反向代理连接http://images.exampe.com.

4.6. 引用包含文件实例

<!--#include file="/include/cn/config.html"-->
<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link rel="shortcut icon" href="<!--#echo var="IMG_HOST"-->/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="<!--#echo var="CSS_HOST"-->/styles/common.css" />
<script type="text/javascript" src="<!--#echo var="JS_HOST"-->/scripts/jquery-1.7.1.min.js"></script>
</head>
<body>
<div id="homeNav"><!--#include virtual="/include/cn/header.html" --></div>
<a href="<!--#echo var=‘ACC_HOST‘-->/register/" class="real">
	<h3><img src="<!--#echo var="IMG_HOST"-->/new/ico_real.png" />注册账户</h3>
</a>
</body>
</html>
时间: 2024-08-28 11:31:27

SSL证书卸载与SSI高级应用的相关文章

python requests 高级用法 -- 包括SSL 证书错误的解决方案

Session Objects会话对象 Session对象在请求时允许你坚持一定的参数.此外,还坚持由Session实例的所有请求的cookie. 让我们坚持在请求时使用 s = requests.Session() s.get('http://httpbin.org/cookies/set/sessioncookie/123456789') r = s.get("http://httpbin.org/cookies") print r.text # '{"cookies&q

阿里云和腾讯云免费SSL证书

概述 什么是SSL证书 通俗的来讲SSL和TSL都是属于网络传输的安全协议,而SSL继承于TSL,且SSL是一种更为安全的加密协议. SSL和TSL的体现: TSL是通过浏览器以http://来访问,默认端口是80: SSL是通过浏览器以https://来访问,默认端口是443. 为什么要使用SSL SSL更加安全 在使用微信小程序开发时与后台数据交互必须使用https传输,即SSL协议 SSL如何获得 SSL证书在很多网站上都有出售,且价格都不便宜(对我来说蛮贵的) 在阿里云和腾讯云上面都有免

添加自签发的 SSL 证书为受信任的根证书

通过 SSL 加密的 HTTPS 连接访问网站时,需要安装并配置一个受信任的 CA 根证书(Trusted CA Root Certificate).平常访问一些加密网站之所以不需要自己安装证书,是因为系统或浏览器已经提前安装了一些受信任机构颁发的证书.但有些时候访问一些组织或个人自己签发证书的网站的时候,就会收到浏览器发出的警告.此时可以将该证书添加到“受信任的根证书颁发机构”存储区,然后就不会再收到安全提示了. 快捷阅读目录 前言 从Windows 自带的浏览器 Internet Explo

Nginx配置免费SSL证书StartSSL,解决Firefox不信任问题

先在StartSSL上申请免费一年的SSL证书,具体过程网上很多教程.然后把申请到的key和crt文件上传到服务器,比如/usr/local/nginx/certs/. Nginx配置SSL证书 直接贴上我的nginx的部分配置: server { listen 443; server_name domain.com www.domain.com ; ssl on; ssl_certificate /usr/local/nginx/ssl/ssl.crt; ssl_certificate_key

Linux下导入SSL证书(配置用于Apache)

三.部署证书 如果使用双向认证,就会有三个私钥和三个证书.分别是 ca.key, ca.crt, server.key, server.crt, client.key, client.crt ,以及给浏览器的 client.pfx .如果使用有 CA 证书的单向认证,证书和私钥就是 ca.key, ca.crt, server.key, server.crt .如果使用无 CA 证书的单向认证,证书和私钥就是 server.key, server.crt . 1.修改httpd.conf文件 *

免费SSL证书(支持1.0、1.1、1.2)

由于公司要开发微信小程序,而微信小程序的接口需要https协议的,并且要支持TLS1.0.TLS1.1.TLS1.2.如果仅仅是为了开发小程序,安全等级又不用太高,可以选择免费的SSL证书 在这里选择腾讯云的证书,申请在 https://console.qcloud.com/ssl 腾讯云里有详细的帮助与文档  https://www.qcloud.com/document/product/400/6814 根据腾讯云的帮助文档去申请安装验证,基本是没什么问题的 安装成功后,使用 https:/

Https系列之二:https的SSL证书在服务器端的部署,基于tomcat,spring boot

Https系列会在下面几篇文章中分别作介绍: 一:https的简单介绍及SSL证书的生成二:https的SSL证书在服务器端的部署,基于tomcat,spring boot三:让服务器同时支持http.https,基于spring boot四:https的SSL证书在Android端基于okhttp,Retrofit的使用 所有文章会优先在:微信公众号"颜家大少"中发布转载请标明出处 一:本文的主要内容介绍 CA证书的下载及相应文件的介绍CA证书在tomcat的部署CA证书在sprin

选择合适的CA购买SSL证书

选择合适的CA购买SSL证书 对于一个只需要DV证书的小网站,理论上所有CA都没问题.你可以随意选择,找一家最便宜的CA就行.任何公共CA都可以直接签发DV证书,并且无需你提供任何信息,为什么要付更多的钱呢?但是,如果你的证书需要用来保护重要的资产,花一点时间仔细选择,确保CA能满足你的所有需求.假如你还需要启用像钉扎这样的高级特性,选择一个CA将会是一个长期的承诺,请更加谨慎地选择.购买SSL证书:https://shop.evtrust.com 服务今时今日,一切都是服务,如今的证书服务正变

CentOS 下对 Nginx + Tomcat 组合的申请 SSL 证书的安装

<CentOS 下对 Nginx + Tomcat 配置 SSL 实现服务器 / 客户端双向认证>介绍的是自己给自己颁发服务器端证书.然后再给客户端颁发证书的情况.如果你已经像你的客户一样厌倦了访问你们的网站时,浏览器弹出的安全警报,那就去申请一个 SSL 证书,如 VeriSign.GlobalSign,一般是几千块钱一年的有效期.本文介绍对于 Nginx + Tomcat 组合的 SSL 购买证书的安装. 1. 单向验证 SSL 证书的安装 1.1 nginx 安装 同<CentOS