nginx配置https

nginx配置https

 

 server {
    #nginx 监听端口,443为默认https端口,ssl指使用https,http2为开启http2
    listen                  443 ssl http2;
    # 服务器名称
    server_name             blog.freesilo.com;

    # 网站根目录 和 无后缀时默认查找文件
    root                    /var/www/wordpress;
    index                   index.html    index.php;

    # 开启 ssl (其实实际是tls)
    ssl                     on;
    ssl_prefer_server_ciphers on;
    # 支持的加密协议
    ssl_protocols           TLSv1 TLSv1.1 TLSv1.2;
    # 支持的加密套件
    ssl_ciphers             HIGH:!RC4:!3DES:!aDSS:!aNULL:!kPSK:!kSRP:!MD5:@STRENGTH:+SHA1:+kRSA;
    # 定义session缓存大小
    ssl_session_cache       shared:TLSSL:16m;
    # 定义session过期时间
    ssl_session_timeout     10m;
    # https证书公钥
    ssl_certificate         /etc/letsencrypt/live/blog.freesilo.com/fullchain.pem;
    # https证书私钥 要注意保存!
    ssl_certificate_key     /etc/letsencrypt/live/blog.freesilo.com/privkey.pem;
    # nginx默认会使用Diffiel-Hellman交换密钥是1024位的,相对不安全,所以需要替换使用更安全的。
    #使用 openssl dhparam -out dh4096.pem 4096 可以生成,然后我将其与网站证书的密钥放到了一起
    ssl_dhparam             /etc/letsencrypt/live/www.zpf-fly.gq/dh4096.pem;

    # 禁止被外站frame嵌入引用
    add_header X-Frame-Options SAMEORIGIN;
    # 为响应头添加要求浏览器使用https重定向的 header
    add_header Strict-Transport-Security max-age=16000000;
}