基于Nginx的SSL证书配置问题整理


我这里没有使用自行颁发的SSL证书,因为那个不受浏览器的信任,当然也没去购买 :D。使用的是StartSSL的免费证书,有效期是一年。至于证书的申请这里不详细说了,只要到StartSSL.COM那里注册用户申请即可,在验证填写个人信息的时候需要详细一些, 第一次由于没有填写完整,几分钟之后就收到 了StartSSL的邮件,说需要我填写完整。直接将个人的信息完整的返回给那个信息之后,几分钟之内就回到了StartSSL的确认邮箱。:P 这里说明他们的服务还是相当好的。
在你完成StartSSL要求的一系列步骤之后会得到ssl.crt和ssl.key两个文件,上传到你的服务器的某个目录中,然后进行以下操作
wget http://cert.startssl.com/certs/ca.pem wget http://cert.startssl.com/certs/sub.class1.server.ca.pemcat ca.pem sub.class1.server.ca.pem>> ca-certs.crtcat ca-certs.crt >> ssl.crt 然后就可以开始配置nginx了这里直接给出nginx.conf的增加内容我拿的我的txp.name来开刀
server {        listen 80;        server_name txp.name www.txp.name;        #rewrite ^/(.*) https://txp.name/$1 permanent;        if ( $http_user_agent ~* [^baiduspider|bing|yahoo|msnbot|soso|sogou|iaskspider|yodao] ) {    rewrite ^(.*) https://www.txp.name$1 permanent;     } }  server  {    listen       443;    server_name  txp.name www.txp.name;    index index.html index.htm index.php;    root  /jiaozhu/htdocs/blog;    ssl on;    ssl_certificate /usr/local/nginx/ssl/ssl.crt;    ssl_certificate_key /usr/local/nginx/ssl/ssl.key;    #limit_conn   crawler  20;                                    location ~ .*.(php|php5)?$    {            #fastcgi_pass  unix:/tmp/php-cgi.sock;      fastcgi_pass  127.0.0.1:9000;      fastcgi_index index.php;      include fcgi.conf;    }        location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$    {      expires      30d;    }    location ~ .*.(js|css)?$    {      expires      1h;    }             if (-f $request_filename/index.html){            rewrite (.*) $1/index.html break;        }        if (-f $request_filename/index.php){            rewrite (.*) $1/index.php;        }        if (!-f $request_filename){            rewrite (.*) /index.php;        }    log_format  access  $remote_addr - $remote_user [$time_local] $request               $status $body_bytes_sent $http_referer               $http_user_agent $http_x_forwarded_for;    access_log  /jiaozhu/logs/access.log  access;    }将txp.name改成你的域名就可以了,我这里进行的是强制使用ssl

使用nginx -t对nginx.conf进行检查,我这里报错(SSL: error:0906D066:PEM routines:PEM_read_bio:bad end line)这是由于在合并ssl.crt的时候出了问题more一下ssl.crt可以看到一行 -----END CERTIFICATE----------BEGIN CERTIFICATE-----但是标准的格式应该是 -----END CERTIFICATE----------BEGIN CERTIFICATE-----改正之后重新使用nginx -t进行检查发现已经正常了。使用nginx -s reload重新启动nginx即可。

我检查了一下在firefox和chrome下都正常,但是ie下却没有样式。我的解决办法是在数据库执行以下句子UPDATE `typecho`.`typecho_options` SET `value` = https://txp.name WHERE `typecho_options`.`name` = siteUrl大家可以访问txp.name看一下效果

相关内容

    暂无相关文章