给http加上s

11年前 7

记得刚毕业,在无锡工作的时候,发现这个国度还有GFW,从那时起对https特别喜欢,传说这样就不会被GFW和谐了。因此曾一度想尽设法给自己的网站申请SSL证书。但是因为技术和money有限,搁置了。很庆幸,到目前为止,我还是很低调的。

用vps很长一段时间了,昨晚突然兴起,添加个https玩玩。大家可以通过http://hjyl.org访问本博客。有啥好处呢?不知道。因为这个是StartSSL免费的SSL证书,可能有局限性,不像https://www.alipay.com/那样真正实现完全加密,而且在浏览器上有个锁的标识,非常有个性,看图,godaddy的更明显。

alipay godaddy

查了很多信息,网上关于StartSSL免费SSL证书的申请和续期教程很多。这里只记录下在lnmp+debian下的具体用法吧。

把ssl.key和ssl.crt放在/usr/local/nginx/conf/vhost下(这个路径问题见下面更新),然后修改你的域名.conf,即nginx配置,主要是添加一个server,和默认的server差不多,不同的是端口,我才发现https用的是443端口,就等于说把原来的hjyl.org:80改成hjyl.org:443,只是默认80端口不需要表示出来。

server
{
listen       80;
server_name hjyl.org www.hjyl.org;
index index.html index.htm index.php default.html default.htm default.php;
root  /home/wwwroot/hjyl.org;include wordpress.conf;
location ~ .*.(php|php5)?$
{
try_files $uri =404;
fastcgi_pass  unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
}……….
}server
{
listen         443;
server_name hjyl.org www.hjyl.org;
index index.html index.htm index.php default.html default.htm default.php;
root  /home/wwwroot/hjyl.org;

ssl on;
ssl_certificate ssl.crt;       #如果证书和此配置文件不在同一目录,需写上路径,例如/home/wwwroot/ssl.crt
ssl_certificate_key ssl.key;   #同上
ssl_session_timeout 5m;

ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
ssl_prefer_server_ciphers   on;

include wordpress.conf;
location ~ .*.(php|php5)?$
{
try_files $uri =404;
fastcgi_pass  unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
fastcgi_param HTTPS on;   #添加这个,是为了在https时,点开的链接也https。
}

………
}

然后/root/lnmp reload,看看效果吧!

测试过IE,chrome,和火狐,就火狐效果好点。chrome好像不支持,郁闷!不管怎样,以前想做没做到的事现在实现了,就这样低调的酷吧!并且继续折腾吧,希望会实现那理想的效果!『如找到更好的技巧,会同时在此页更新的』

2013/04/22  更新:

几经波折,绞尽脑汁,终于弄明白了lnmp下的SSL一些问题。(在此特别感谢Rvsien指点)

ssl_certificate ssl.crt;
ssl_certificate_key ssl.key;

此时,它调用的是/usr/local/nginx/conf/下的证书和key,所以这个配置建议还是带上证书和key的路径,例如

ssl_certificate /usr/local/nginx/conf/vhost/ssl.crt;
ssl_certificate_key /usr/local/nginx/conf/vhost/ssl.key;

别小看https的更换,从SEO上讲,是一个新站的开始,等于换了一个域名。所以确认换https时,我们将http 301重定向到https。只需要如此配置:

server
{
listen       80;
server_name hjyl.org www.hjyl.org;
rewrite ^(.*) https://$server_name$1 permanent; #http 301重定向到https规则
……..

还有特别说明,如果firefox里地址栏不显示一个锁子的话,可能是页面使用了http的链接,或者使用了http的外网的链接资源导致的,它的意思是:页面部分加密。

7 条评论

  1. #1

    除了google都对https支持的不好

  2. #2

    https就不会被墙么。

  3. #3

    搞的很复杂的样子,个人博客还要搞https感觉有点儿大材小用哦。

  4. #4

    个人博客无所谓了

评论 Qiankun 取消评论