也不知道是从什么时候开始,chrome对于没有https的网站都会提示不安全,这显然让人很不爽。之前网站架在Digital Ocean的时候,用Certbot安装了免费的SSL证书,算是解决了这个问题。Certbot这个东西有个优点就是他会给你把nginx.conf 配置好, 对于我这种不咋熟悉nginx以及其他所有东西的人来说就很方便。但是现在网站架在阿里云了,也就想弄一些更加“阿里云化”的解决方案,于是用了它提供的免费证书。证书申请通过后会可以下载到两个文件:
这两个文件可以用sftp拷贝到指定目录……不再赘述,重点在于修改nginx.conf中的内容,nginx.conf可能会位于/usr/local/nginx/conf/目录下,https显然不能也走80端口,这里我将设置好的内容发上来做一个参考。
server
{
listen [::]:80 default_server ipv6only=on;
server_name skelviper.top;
index index.html index.htm index.php;
root /home/wwwroot/default;
#error_page 404 /404.html;
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
rewrite /wp-admin$ host$uri/ permanent;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
include enable-php.conf;
location /nginx_status
{
stub_status on;
access_log off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
access_log /home/wwwlogs/access.log;
listen 443 ssl;
ssl_certificate cert/2400051_skelviper.top.pem;
ssl_certificate_key cert/2400051_skelviper.top.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;
}