ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

Docker+Nginx+Ssl

2021-02-18 09:32:34  阅读:145  来源: 互联网

标签:log ssl soft Nginx html Ssl conf Docker nginx


docker安装nginx并配置域名

创建挂载目录
/soft/nginx/conf
/soft/nginx/conf/conf.d
/soft/nginx/html
/soft/nginx/log
/soft/nginx/ssl   //证书先放到这里
创建配置文件
  • vim /soft/nginx/conf/conf.d/default.conf

server {
   listen       80;
   server_name  localhost;

   #charset koi8-r;
   #access_log  /var/log/nginx/log/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;
   #}
}
  • vim /soft/nginx/conf/nginx.conf


user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
   worker_connections  1024;
}


http {
   include       /etc/nginx/mime.types;
   default_type  application/octet-stream;

   log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                     '$status $body_bytes_sent "$http_referer" '
                     '"$http_user_agent" "$http_x_forwarded_for"';

   access_log  /var/log/nginx/access.log  main;

   sendfile        on;
   #tcp_nopush     on;

   keepalive_timeout  65;

   #gzip  on;

   include /etc/nginx/conf.d/*.conf;
}
  • vim /soft/nginx/html/index.html

<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
   <title>系统时间</title>
</head>
<body>
<div id="datetime">
   <script>
       setInterval("document.getElementById('datetime').innerHTML=new Date().toLocaleString();", 1000);
   </script>
</div>
</body>  

 

启动nginx并配置挂载的目录
docker run  -d \
-p 80:80 \
-v /soft/nginx/html:/usr/share/nginx/html \
-v /soft/nginx/log:/usr/share/nginx/log \
-v /soft/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /soft/nginx/conf/conf.d/default.conf:/etc/nginx/conf.d/default.conf \
-v /etc/localtime:/etc/localtime:ro \
--name nginx  \
nginx:1.10  
-d: 后台运行容器,并返回容器ID;
-p: 指定端口映射,格式为:主机(宿主)端口:容器端口
-v: 挂载后的目录:原目录
--name: 为容器指定一个名称;
\:换行
把下载的证书长传到nginx容器中
docker cp /soft/nginx/ssl/1_zhezhao.work_bundle.crt  723959a72914:/etc/nginx/ssl
docker cp /soft/nginx/ssl/2_zhezhao.work.key 723959a72914:/etc/nginx/ssl
修改default.conf配置文件
server {
   listen       80 ssl;
   server_name  zhezhao.work;
#nginx容器内证书地址
ssl_certificate     /etc/nginx/ssl/1_zhezhao.work_bundle.crt;
   #nginx容器内证书地址
ssl_certificate_key  /etc/nginx/ssl/2_zhezhao.work.key;

ssl_session_cache    shared:SSL:1m;
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;

   location / {
       root   /usr/share/nginx/html;
       index  index.html index.htm;
  }


   location = /50x.html {
       root   /usr/share/nginx/html;
  }


}
   server {
       listen       443 ssl;
       server_name  zhezhao.work;

       ssl_certificate     /etc/nginx/ssl/1_zhezhao.work_bundle.crt;
       ssl_certificate_key  /etc/nginx/ssl/2_zhezhao.work.key;

       ssl_session_cache    shared:SSL:1m;
       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;

       location / {
           root   html;
           index  index.html index.htm;
      }
  }
重启nginx容器
docker restart nginx

 

标签:log,ssl,soft,Nginx,html,Ssl,conf,Docker,nginx
来源: https://www.cnblogs.com/shuxiaosheng/p/14410589.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有