环境说明:
- 阿里云 Centos 7.4
- fecshop 安装方式: docker安装
- 证书:Let's encrypt
Let's encrypt安装
git clone https://github.com/letsencrypt/letsencrypt.git
# cd letsencrypt
# ./letsencrypt-auto certonly --standalone --email 你邮箱地址 -d 你的域名
- 记得将上面的邮箱和域名替换成自己的,上面命令中的certonly表示只获取证书,不安装;-d 参数可以多个,表示增加多个域名
期间会出现两个确认。依次输入 A, Y。
如图(如果看到我的域名,求放过):

获取成功后:你可以到/etc/letsencrypt/live/你的域名/目录下找到相关的证书文件有4个:

----注意这里有个坑,因为这个耽误了我一个多小时----
这里我们看到的是软链接,其实真实目录在以下位置而且名字还多个1(这是坑)。
/etc/letsencrypt/archive/你的域名

记住这个路径,下面配置我们会用到。
配置nginx, 配置docker-compose.yml
- 阿里云记得开放443端口
- docker-compose.yml

上面的路径就是要用到上面所说的证书路径
最后是nginx配置,你可以参照的写,贴代码:
server {
listen 80;
listen 443 ssl http2;
server_name 你的域名;
ssl on;
#这里是http转https配置
if ($server_port !~ 443) {
rewrite ^(/.*)$ https://$host$1 permanent;
}
ssl_certificate /etc/letsencrypt/archive/你的域名/fullchain1.pem;
ssl_certificate_key /etc/letsencrypt/archive/你的域名/privkey1.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
#这里是http转https配置
error_page 497 https://$host$request_uri;
root /www/web/fecshop/appserver/web;
server_tokens off;
include none.conf;
index index.php index.html index.htm;
access_log /www/web_logs/access.log wwwlogs;
error_log /www/web_logs/error.log notice;
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
include fcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
expires 30d;
}
location ~ .*\.(js|css)?$ {
expires 12h;
}
}
配置好后,
docker-compose restart web 重启web容器
到这里HTTPS配置完成。不懂留言
本文由 Axin 创作,采用 知识共享署名 3.0 中国大陆许可协议 进行许可。
可自由转载、引用,但需署名作者且注明文章出处。