nginx配置免费SSL证书及证书定时更新
2017-10-20 22:40
483 查看
环境 contos 6,证书发行Let's Encrypt
证书生成前提是域名是可用的,即已经备案通过并且有DNS解析到了具体IP
1、安装epel,
>yum install epel-release
2、下载certbot证书生成工具certbot-auto
>wget https://dl.eff.org/certbot-auto --no-check-certificate
3、安装工具的依赖
>chmod +x certbot-auto
>./certbot-auto -n
4、生成证书
单域名:
>./certbot-auto certonly --email my@163.com --agree-tos --no-eff-email --webroot -w /usr/local/nginx/html/xue/ -d
www.xue37.cn
注意:替换邮箱、网站目录和域名
多域名:
>./certbot-auto certonly --email my@163.com --agree-tos --no-eff-email --webroot -w /usr/local/nginx/html/xue/ -d
www.xue37.cn -d
xue37.cn
证书生成在/etc/letsencrypt/live/www.xue37.cn/目录下(具体生成地址执行完命令有提示信息)
5、证书延期(因为证书有效期为90天)
certbot-auto工具支持证书延期操作,因此可以使用crontab定时任务定时自动延期
>0 3 * * * /root/certbot-auto renew --disable-hook-validation --renew-hook "/usr/local/nginx/sbin/nginx -s reload"
每天3点进行证书延期,crontab表达式自己可以百度
注意:自己可以先单独执行一下:/root/certbot-auto renew --disable-hook-validation --renew-hook "/usr/local/nginx/sbin/nginx -s reload"
我这里提示The following certs are not due for renewal yet,表示证书未到期,没有其他错误。因此为了防止证书失效时间过久,这里可以设置为每天都进行延期操作
6、nginx增加证书配置
server
{
listen 443 ssl;
server_name www.xue37.cn; ##这里是你的域名
ssl_certificate /etc/letsencrypt/live/www.xue37.cn/fullchain.pem; #前面生成的证书,改一下里面的域名就行
ssl_certificate_key /etc/letsencrypt/live/www.xue37.cn/privkey.pem; #前面生成的密钥,改一下里面的域名就行
ssl_ciphers ECDHE-RSA-AES256-SHA384:AES256-SHA256:RC4:HIGH:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!AESGCM;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
access_log /data/application/logs/xue.access.log main;
location ^~ /bot {
proxy_pass http://xue-server; include proxy-params.conf;
}
location / {
root html/xue;
index index.html index.htm;
}
location = /50x.html {
root html;
}
}
7、设置80端口301到443
修改nginx配置:
server
{
listen 80;
server_name localhost;
location /.well-known/ {
add_header Content-Type 'text/plain;';
root /usr/local/nginx/html/xue;
}
location / {
return 301 https://www.xue37.cn$request_uri;
}
}
注意:nginx修改后需要重启:/usr/local/nginx/sbin/nginx -s reload
注意:nginx配置需要处理
location ~ /\.
{
deny all;
}
这段配置删掉或注释掉或在这段配置前面加上(如果没有这段配置请忽略)
location ~ /.well-known {
allow all;
}
证书生成前提是域名是可用的,即已经备案通过并且有DNS解析到了具体IP
1、安装epel,
>yum install epel-release
2、下载certbot证书生成工具certbot-auto
>wget https://dl.eff.org/certbot-auto --no-check-certificate
3、安装工具的依赖
>chmod +x certbot-auto
>./certbot-auto -n
4、生成证书
单域名:
>./certbot-auto certonly --email my@163.com --agree-tos --no-eff-email --webroot -w /usr/local/nginx/html/xue/ -d
www.xue37.cn
注意:替换邮箱、网站目录和域名
多域名:
>./certbot-auto certonly --email my@163.com --agree-tos --no-eff-email --webroot -w /usr/local/nginx/html/xue/ -d
www.xue37.cn -d
xue37.cn
证书生成在/etc/letsencrypt/live/www.xue37.cn/目录下(具体生成地址执行完命令有提示信息)
5、证书延期(因为证书有效期为90天)
certbot-auto工具支持证书延期操作,因此可以使用crontab定时任务定时自动延期
>0 3 * * * /root/certbot-auto renew --disable-hook-validation --renew-hook "/usr/local/nginx/sbin/nginx -s reload"
每天3点进行证书延期,crontab表达式自己可以百度
注意:自己可以先单独执行一下:/root/certbot-auto renew --disable-hook-validation --renew-hook "/usr/local/nginx/sbin/nginx -s reload"
我这里提示The following certs are not due for renewal yet,表示证书未到期,没有其他错误。因此为了防止证书失效时间过久,这里可以设置为每天都进行延期操作
6、nginx增加证书配置
server
{
listen 443 ssl;
server_name www.xue37.cn; ##这里是你的域名
ssl_certificate /etc/letsencrypt/live/www.xue37.cn/fullchain.pem; #前面生成的证书,改一下里面的域名就行
ssl_certificate_key /etc/letsencrypt/live/www.xue37.cn/privkey.pem; #前面生成的密钥,改一下里面的域名就行
ssl_ciphers ECDHE-RSA-AES256-SHA384:AES256-SHA256:RC4:HIGH:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!AESGCM;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
access_log /data/application/logs/xue.access.log main;
location ^~ /bot {
proxy_pass http://xue-server; include proxy-params.conf;
}
location / {
root html/xue;
index index.html index.htm;
}
location = /50x.html {
root html;
}
}
7、设置80端口301到443
修改nginx配置:
server
{
listen 80;
server_name localhost;
location /.well-known/ {
add_header Content-Type 'text/plain;';
root /usr/local/nginx/html/xue;
}
location / {
return 301 https://www.xue37.cn$request_uri;
}
}
注意:nginx修改后需要重启:/usr/local/nginx/sbin/nginx -s reload
注意:nginx配置需要处理
location ~ /\.
{
deny all;
}
这段配置删掉或注释掉或在这段配置前面加上(如果没有这段配置请忽略)
location ~ /.well-known {
allow all;
}
相关文章推荐
- nginx配置SSL证书(使用startSSL申请到的免费证书)
- SSL证书申请及nginx配置证书
- Nginx + https + 免费SSL证书配置指南
- nginx 配置 Wosign 申请的免费的 SSL 证书
- StartSSL免费的HTTPS证书颁发机构及nginx 的ssl配置
- Ubuntu 17.04 编译安装 Nginx 1.9.9 配置 https 免费证书
- nginx配置免费的ssl证书,支持https安全访问
- ssl证书申请以及nginx证书的配置
- nginx配置https(免费证书)
- Nginx配置SSL证书部署HTTPS网站的方法(颁发证书)
- Ubuntu 17.04 编译安装 Nginx 1.9.9 配置 https 免费证书
- 一个ip对应多个域名多个ssl证书配置-Nginx实现多域名证书HTTPS
- 在LNMP或Nginx上配置NameCheap免费SSL证书
- 转自《https安全链接的配置教程:startSSl免费证书申请与nginx的https支持配置》
- Nginx+tomcat+ssl免费证书配置
- HTTPS证书验证流程及SSL证书生成步骤【附nginx开启https配置】
- nginx配置https的方法示例(免费证书)
- Nginx + https + 免费SSL证书配置指南
- Nginx + https + 免费SSL证书配置指南
- 阿里云免费SSL证书申请与安装使用-附Nginx,Apache,IIS 6,IIS 8配置SSL教程