nginx配置ssl
1:申请下载ssl证书。我这里是在阿里云申请的证书,但是我的域名是在百度云买的,
所以在申请的时候需要在在百度云上设置dns解析。按照阿里云的步骤就可以了。
2:申请完成之后,将得到的两个文件放入服务器中,就是.pem
文件和.key
文件,放入nginx配置文件的cert文件中。
3:修改nginx.conf配置文件。直接添加即可
server {
listen 443;
server_name www.xxxxxxxx.com;
ssl on;
root html;
index index.html index.htm;
ssl_certificate cert/2147538960028.pem;
ssl_certificate_key cert/2147538946028.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
root html;
index index.html index.htm;
}
#解析PHP文件
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
4:重新启动nginx即可。
nginx -s reload
5:输入网址检验即可
https://www.xxxxxxx.com
6:安装时遇到的问题。
a、申请证书是没有去域名服务商那里将域名解析的值修改。
b、配置好文件访问.php文件时,访问不了,直接将php文件下载下来了。
解决方法:在nginx配置中添加即可。
#解析PHP文件
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}