Let’s Encrypt+Nginx虚拟主机设置

完整配置如下:

server
{
listen 443 ssl; //如果需要spdy也可以加上,lnmp1.2及其后版本都默认支持spdy,lnmp1.3 nginx 1.9.5以上版本默认支持http2
server_name www.xiaokyun.com; //这里是你的域名
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/www.xiaokyun.com; //网站目录
ssl_certificate /etc/letsencrypt/live/www.xiaokyun.com/fullchain.pem; //前面生成的证书,改一下里面的域名就行,不建议更换路径
ssl_certificate_key /etc/letsencrypt/live/www.xiaokyun.com/privkey.pem; //前面生成的密钥,改一下里面的域名就行,不建议更换路径
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;

include wordpress.conf; //这个是伪静态根据自己的需求改成其他或删除
#error_page 404 /404.html;
location ~ [^/].php(/|$)
{
# comment try_files $uri =404; to enable pathinfo
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf; //lnmp 1.0及之前版本替换为include fcgi.conf;
#include pathinfo.conf;
}

location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}

location ~ .*.(js|css)?$
{
expires 12h;
}

access_log off;
}

需将上述配置根据自己的实际情况修改后,添加到虚拟主机配置文件最后面。

添加完需要执行:

/etc/init.d/nginx reload

重新载入配置使其生效。

如果需要HSTS,可以加上

add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";

Published by

@XiaoKyun

双鱼男,过分热心的好人。