因为ssl证书过期了,所以想要重新弄一个,这里看到沃通数字证书便试了下。好像还真的可以。不过要注册一个账号才能有一个一年期限的证书,不过也还不错。
这里选方式二,自己提交,不然没有.key文件,会搞得特别纠结。当然也可能是我对证书这块不了解。因为到时候弄好后给你下载的只有crt文件。目前我还不知道怎么从crt里生产个key文件或者pem文件来
既然要自己提交csr那就需要用openssl生成一个了
生成服务器私钥先 openssl genrsa -des3 -out servername.key 2048 创建证书签名请求(Certificate Signing Request (CSR)) openssl req -new -key server.key -out server.csr 清除以SSL启动Nginx时提示必须输入密钥 cp server.key servername.key.org openssl rsa -in servername.key.org -out servername.key
这个可能要等2-3个小时,也有可能一天。
下载后有2个crt文件。
使用其中的一个配置到nginx里面
server {
listen 80;
server_name www.xxx.com;
#实现http到https的跳转规则
if ($host ~* www.xxx.com) {
rewrite ^/$ https://www.xxx.com/ permanent;
}
index index.html index.php index.htm;
root /home/www/html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location /\. {
deny all;
}
location / {
if (-f $request_filename) {
expires 30d;
break;
}
if (!-e $request_filename) {
rewrite ^(.+)$ /index.php last;
}
}
location ~ .*\.php$ {
root /home/www/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
server{
server_name www.xxx.com;
listen 443;
root /home/www/html;
index index.html index.htm index.php;
ssl on;
ssl_certificate /usr/local/nginx/conf/www.crt;
ssl_certificate_key /usr/local/nginx/www.key;
location /\. {
deny all;
}
location / {
if (-f $request_filename) {
expires 30d;
break;
}
if (!-e $request_filename) {
rewrite ^(.+)$ /index.php last;
}
}
location ~ .*\.php$ {
root /home/www/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param HTTPS $fastcgi_https;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}这样就完成了!
本文出自 “孜孜不倦的学习着...” 博客,请务必保留此出处http://jonyisme.blog.51cto.com/3690784/1662453
原文地址:http://jonyisme.blog.51cto.com/3690784/1662453