1. 阿里云官网申请证书:数字证书管理服务管理控制台 (aliyun.com)
2. docker安装nginx并挂载
3. 配置证书并启动4.conf文件配置
一:阿里云官网证书下载
阿里云申请证书,第一次可以申请一年,往后3个月申请一次
申请完成后点击下载(会生成私钥密钥文件,后面要用)
2. docker安装nginx并挂载
推荐看这篇文章跟着配置
Docker 安装 Nginx 容器 (完整详细版)_docker nginx-CSDN博客
按照这个博客安装并挂载nginx,同时配置证书需要再创建一个ssl文件夹,然后将ssl的密钥私钥文件直接放到ssl这个文件夹下
3. 配置证书并启动
最后是配置命令,直接运行即可!
docker run --name nginx -p 80:80 -p 443:443 -v /home/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /home/nginx/conf/conf.d:/etc/nginx/conf.d -v /home/nginx/log:/var/log/nginx -v /home/nginx/html:/usr/share/nginx/html -v /home/nginx/ssl:/etc/nginx/ssl --privileged=true -d --restart=always nginx:latest
4. nginx的配置文件
我是看见default.conf配置文件
server {
listen 80;
listen [::]:80;
server_name localhost;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
server {
listen 443 ssl;
server_name mkdd.aisce.net;
#证书文件名称
ssl_certificate_key /etc/nginx/ssl/kevinyang.fun.key;
#私钥文件名称 .crt和.pem都可以用
ssl_certificate /etc/nginx/ssl/kevinyang.fun.pem;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
location / {
root /usr/share/nginx/html;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location /api/ {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8585/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}