Let’s Encrypt HTTPS证书申请

转载地址:https://www.52chenqi.cn/?p=29python


HTTPS(全称:Hyper Text Transfer Protocol over Secure Socket Layer),是以安全为目标的HTTP通道,简单讲是HTTP的安全版。即HTTP下加入SSL层,HTTPS的安全基础是SSL,所以加密的详细内容就须要SSL。 它是一个URI scheme(抽象标识符体系),句法类同http体系。用于安全的HTTP数据传输。https:URL代表它使用了HTTP,但HTTPS存在不一样于HTTP的默认端口及一个加密/身份验证层(在HTTP与TCP之间)。这个系统的最初研发由网景公司(Netscape)进行,并内置于其浏览器Netscape Navigator中,提供了身份验证与加密通信方法。如今它被普遍用于万维网上安全敏感的通信,例如交易支付方面。nginx

原理就不讲了,主要讲一下如何把咱们的网站变成https以及https的有点。git

1、从HTTP到HTTPSgithub

我这里是到Let’s Encrypt上面申请免费的证书,他的证书有效期为90天,但能够经过再次申请。下面我就来试试好很差用。web

Step1: 建立Let’s Encrypt帐户私钥
openssl genrsa 4096 > account.key浏览器

Step2: 为您的域建立证书签名请求(CSR)安全

# Generate a domain private key (if you haven't already)
openssl genrsa 4096 > domain.key
# For a single domain 单域名
openssl req -new -sha256 -key domain.key -subj "/CN=yoursite.com" > domain.csr 
# For multiple domains 多域名 (use this one if you want both www.yoursite.com and yoursite.com) 
openssl req -new -sha256 -key domain.key -subj "/" -reqexts SAN -config <(cat /etc/ssl/openssl.cnf <(printf "[SAN]\nsubjectAltName=DNS:yoursite.com,DNS:www.yoursite.com")) > domain.csr

Step3:让你的网站主机challenge 文件session

# Make some challenge folder (modify to suit your needs)
mkdir -p /var/www/challenges/
# Example for nginxserver {    listen 80;    server_name yoursite.com www.yoursite.com;    location /.well-known/acme-challenge/ {        alias /var/www/challenges/;        try_files $uri =404;
    }

    ...the rest of your config
}

Step4: 得到签名证书!dom

# 下载acme_tiny.py 这个是github地址https://github.com/diafygi/acme-tiny.git
# Run the script on your server
python acme_tiny.py --account-key ./account.key --csr ./domain.csr --acme-dir /var/www/challenges/ > ./signed_chain.crt

Step5: 安装证书ide

配置nginx.conf

server {    listen 443 ssl;    server_name yoursite.com, www.yoursite.com;    ssl_certificate /path/to/signed_chain.crt;    ssl_certificate_key /path/to/domain.key;    ssl_session_timeout 5m;    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;    ssl_ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA;    ssl_session_cache shared:SSL:50m;    ssl_dhparam /path/to/server.dhparam;    ssl_prefer_server_ciphers on;

    ...the rest of your config
}server {    listen 80;    server_name yoursite.com, www.yoursite.com;    location /.well-known/acme-challenge/ {        alias /var/www/challenges/;        try_files $uri =404;
    }

    ...the rest of your config
}

http自动跳转到https

server {
   listen 80;
   server_name www.52chenqi.cn 52chenqi.cn;
   location /.well-known/acme-challenge/ {
     root /usr/local/nginx/ssl/www/;
     try_files $uri =404;
   }
   location / {
     rewrite ^(.*) https://$server_name$1 permanent;
   }
}

2、优势

一、HTTPS具备更好的加密性能,避免用户信息泄露;

二、HTTPS复杂的传输方式,下降网站被劫持的风险;

三、搜索引擎已经全面支持HTTPS抓取、收录,而且会优先展现HTTPS结果;

四、HTTPS绿锁表示能够提高用户对网站信任程度;

五、能够有效防止山寨、镜像网站等

相关文章
相关标签/搜索