docker配置nginx的https 最简单教程, 编译成镜像

举报
拿我格子衫来 发表于 2022/03/17 22:33:36 2022/03/17
1.4k+ 0 0
【摘要】 nginx的镜像中 几个重要的配置文件夹 etc/nginx/conf.d/*.conf; /usr/share/nginx   /etc/nginx/conf.d/default.conf; server { listen 80; listen [::]:80; server_nam...

nginx的镜像中 几个重要的配置文件夹

etc/nginx/conf.d/*.conf;

/usr/share/nginx

/etc/nginx/conf.d/default.conf;


      server {
          listen       80;
          listen  [::]:80;
          server_name  localhost;
         #charset koi8-r;
         #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;
         #}
      }
  
 

/etc/nginx/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;
      }
  
 

分析nginx.conf 得知 在配置文件里 引入了/etc/nginx/conf.d 下的所有以.conf为结尾的配置文件

我们可以新建一个mynginx.conf 文件 编写https的配置

需要将https的证书存放在 /mywebapp/ssl目录下


      server {
          listen       443 ssl;
          server_name  localhost;
          ssl_certificate      /mywebapp/ssl/server.crt;
          ssl_certificate_key  /mywebapp/ssl/server.key;
          ssl_session_cache    shared:SSL:1m;
          ssl_session_timeout  5m;
          ssl_ciphers  HIGH:!aNULL:!MD5;
          ssl_prefer_server_ciphers  on;
          location / {
              root   /mywebapp/www;
              index  index.html index.htm;
          }
      }
  
 

使用命令  即可启动镜像, 访问https://IP 即可

docker run -d -p 443:443 doc1 
 

文章来源: fizzz.blog.csdn.net,作者:拿我格子衫来,版权归原作者所有,如需转载,请联系作者。

原文链接:fizzz.blog.csdn.net/article/details/106759548

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

作者其他文章

评论(0

抱歉,系统识别当前为高风险访问,暂不支持该操作

    全部回复

    上滑加载中

    设置昵称

    在此一键设置昵称,即可参与社区互动!

    *长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

    *长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。