欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 文化 > docker 安装nginx并配置https (个人记录)

docker 安装nginx并配置https (个人记录)

2025/3/19 17:43:01 来源:https://blog.csdn.net/qq_67801847/article/details/140920065  浏览:    关键词:docker 安装nginx并配置https (个人记录)

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;}
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词