HTTPS 排名

谷歌不是说提升 HTTPS 的排名吗?网站应该开始用这货了。我自己是在 NameCheap 买证书的啦,自己找到算最便宜的了。当然,也有免费的 STARTSSL。最基本的 SSL 证书价格跟一个正常的  .com 域名的价钱差不多。

NGINX 虽然支持 Server Name Indication,但是游览器的支持率不高,也就是说 NGINX 不支持一台服务器安装 N 个 SSL 证书的,每个 HTTPS 的网站需要一个独立 IP。(wildcard  或者 Subject Alternative Names (SAN) 证书可以忽略这段话)

NGINX 的 HTTPS 配置详见:mozilla

完全向前保密

事先申明:这篇文章不是给 PFS 翻译,只是我个人的见解。欲知 PFS 是神马,请自己阅读这里(英文)和这里(英文)。

完全向前保密(Perfect Forward Secrecy,PFS)使用“会话密钥(Session Key)”在会话结束后就过期。“会话密钥”是一个长期密钥(Long-Term Key)的衍生出来的密钥,不会透露额外的密钥。所以,简单来说,黑客今天截取一些通讯资料,明天或者有更好更快的机器帮助他解密,就算破解到这个“会话密钥”,他也只能看到这个会话的内容,其他的通讯是不能用这个已破解的密钥来解密。如果你没有使用 PFS,一旦解密密钥被破解,网站的加密也统统给破解掉了。

软件需求:

  • nginx 1.1.13+
  • nginx 的 ngx_http_ssl_module 模块
  • 一个有效的 SSL 证书
  • OpenSSL 1.0.1+

Forward Secrecy

因为 PFS 使用了『迪菲-赫尔曼加密法』,所以需要一些额外的配置。 Continue reading 完全向前保密

分享几个 Nginx rewrite

Vanilla Forum http://vanillaforums.org/

location / {
	try_files $uri $uri/ /index.php?p=$uri&$args;
}

WordPress http://wordpress.org

根目录

location / {
	try_files $uri $uri/ /index.php?$args;
}

其他目录,例如:example.com/blog/

location /blog/ {
    try_files $uri $uri/ /blog/index.php?$args;
}

遇到502 时自动转跳到维修页

error_page 502 = @fallback;

location @fallback {
    rewrite ^(.*)$ /你的维修页.html break;
}

YOURLS (Your Own URL Shortener)http://yourls.org

location / {
	try_files $uri $uri/ /yourls-loader.php;
}

重写 jQuery-x.x.x.min.js 到最新版(x = 单位数字)

location ~* jquery\-(\d|\.)*\.min\.js$ {
     rewrite ^ http://example.com/assets/js/latest-jquery.min.js last;

     alias /绝对路径/jquery-1.4.4.min.js;

     # 绝对路径 - 例如:/www/my-website/assets/js/jquery-1.4.4.min.js

}

更新:
改用 alias,省掉 redirect 的时间
可以参考 nginx 的官方维基[Link]

HTML5 Boilerplate 的时间戳

例如:

<!-- 旧的时间戳 -->
<link rel="stylesheet" href="css/anotherstyle.css?ver=2">
<!-- 新的时间戳 -->
<link rel="stylesheet" href="css/anotherstyle.2.css">

注:文件名保持不变,还是 anotherstyle.css

重写方法:

location ~* (.+)\.(\d+)\.(js|css|png|jpg|jpeg|gif)$ {
   try_files $uri $1.$3;
}

更新 – HTML5 Boilerplate 官方语法 via

## 这个时间戳不适合配合 W3CTotalCache 这款插件一起使用。

LNMP:nginx 安装新模块

使用军哥的 LNMP 安装包应该知道升级 nginx 很容易把

注:
(1) 本文章只提供参考。事前要备份,如发现问题还是请教达人。
(2) 本文章只适合 LNMP.org 的安装包

第一步

打开 nginx 自动升级脚本 /LNMP安装包路径/upgrade_nginx.sh

第二步

找到

./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6

第三步

--with-ipv6 后门添加你要安装的模块;例如:

  • mp4 模块 --with-http_mp4_module
  • flv 模块 --with-http_flv_module

如:

./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6 --with-http_mp4_module --with-http_flv_module

添加后保存,运行脚本
/LNMP安装包路径/upgrade_nginx.sh
(可以用这个方法安装其他 nginx 模块)

第四步

在 server{} 添加模块适当的代码,然后保存并重启 nginx

server {
  listen 80;
  server_name example.com;
  # 省略掉 n 行

  # mp4 模块
  location ~* .*.(?:m4a|mp4|mov)$ {
    mp4;
    mp4_buffer_size     1M;
    mp4_max_buffer_size 5M;
  }

  # flv 模块
  location ~* .flv$ {
     flv;
  }
}

扩展阅读:nginx.org #1 | #2