首先呢,在购买ssl的地方,它自动生成了私匙,但是默认为了安全传输,都加上了密码(passphrase),在nginx上使用相当不方便,所以需要使用openssl解密开私匙。
(我这里用root用户直接修改,非root可能需要sudo)
cp certificate.key certificate.key.backup
openssl rsa -in certificate.key.backup -out certificate.key
nginx还需要做一些调整,使用ssl证书,nginx.conf
server {
listen 443;
server_name yourdomain.com;
root /usr/share/nginx/www;
index index.html index.htm index.php;
ssl on;
ssl_certificate /etc/nginx/ssl/certificate.crt;
ssl_certificate_key /etc/nginx/ssl/certificate.key;
}
自此,nginx下ssl配置完毕!(可以不解密直接修改nginx.conf,但是需要每次启动的时候手动输入密码,不然会无法访问!)
——附上没有解密的时候出现的提示——
Starting nginx: Enter PEM pass phrase:(这里让你输入密码)
—-如果密码错误
nginx: [emerg] SSL_CTX_use_PrivateKey_file(“/usr/local/ssl/certificate.key”) failed
[FAILED]
然后启动失败。
—-如果密码正确
Starting nginx: Enter PEM pass phrase:
[ OK ]
Starting php: [ OK ]
留言