一、问题描述

阿里云 Ubuntu 系统 https 证书按照官方说明配置成功,并且正确绑定域名 jhfs.fun。但 docker 中的各项服务无法正常使用 https 请求。

二、原因分析

docker-lnmp 中的 nginx 配置与主系统中的 nginx 冲突

三、解决方案

关闭主系统中的 nginx 服务,在 docker-lnmp 中重新配置 https 服务

步骤 1 : 关闭主系统中 nginx 服务

1
systemctl stop nginx

步骤 2 : 运行 docker-lnmp (如果已经安装可以先移除)

1
2
3
4
5
6
7
8
9
10
11
docker run -dit \
-p 80:80 \
-p 443:443 \
-p 3306:3306 \
-p 9000:9000 \
-v /ssl:/ssl \
-v /var/www:/www \
-v /var/mysql:/data/mysql \
--privileged=true \
--name=lnmp \
2233466866/lnmp

步骤 3 : 进入 docker-lnmp 配置 nginx 并重启服务

进入 docker-lnmp

1
docker exec -it (CONTAINER ID) /bin/bash
1
vi /usr/local/nginx/conf/nginx.conf

在 nginx.conf 中补充 https server 配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
server {
listen 443 ssl;

server_name jhfs.fun;
root /www;
index index.php index.html index.htm;

ssl_certificate /ssl/9752654_jhfs.fun.pem;
ssl_certificate_key /ssl/9752654_jhfs.fun.key;

ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;

ssl_prefer_server_ciphers on;
location / {
index index.php index.html index.htm;
}

location ~* \.php {
include fastcgi_params;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}

重启 nginx

1
systemctl restart nginx

四、过程记录

问题 1: http 可以正常打开 php.info,https 执行“下载”操作

原因:缓存原因,直接换个浏览器或者清理缓存可解决

五、总结备忘

后端传到客户端同样的字符串可能因为 iOS 和 Android 平台差异而显示异常,同时实现两端相关显示时需要充分对比测试。