Docker 部署 Nginx SSl 方式


  1. 部署前准备
    1. Docker环境
    2. 证书
  2. 拉取Nginx镜像
    docker pull nginx
  3. 配置相关文件
    1mkdir -p  /home/nginx/conf
    2mkdir -p  /home/nginx/cert
    3    (cert 目录中放置证书文件(2个))
     1 vim /home/nginx/conf/nginx.conf
     2 
     3 
     4 
     5 user  nginx;
     6 worker_processes  1;
     7 
     8 
     9 error_log  /var/log/nginx/error.log warn;
    10 pid        /var/run/nginx.pid;
    11 
    12 
    13 
    14 
    15 events {
    16     worker_connections  1024;
    17 }
    18 
    19 
    20 
    21 
    22 http {
    23     include       /etc/nginx/mime.types;
    24     default_type  application/octet-stream;
    25 
    26 
    27     log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    28                       '$status $body_bytes_sent "$http_referer" '
    29                       '"$http_user_agent" "$http_x_forwarded_for"';
    30 
    31 
    32     access_log  /var/log/nginx/access.log  main;
    33 
    34 
    35     sendfile        on;
    36     #tcp_nopush     on;
    37 
    38 
    39     keepalive_timeout  65;
    40 
    41 
    42     #gzip  on;
    43 
    44 
    45     #include /etc/nginx/mine/conf.d/*.conf;
    46     server {
    47        listen 80;
    48        server_name www.xxxxxx.tech;
    49        rewrite ^(.*)$ https://$host$1 permanent;
    50     }
    51     server {
    52         listen       443 ssl;
    53         server_name  localhost;
    54         server_name  www.xxxxxx.tech;
    55         ssl_certificate  ./cert/2026015_xxxxxx.tech.pem;
    56         ssl_certificate_key  ./cert/2026015_xxxxxx.tech.key;
    57         ssl_session_timeout 5m;
    58         ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    59         ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    60         ssl_prefer_server_ciphers on;
    61         location / {
    62            root   /usr/share/nginx/html;
    63            index  index.html index.htm;
    64         }
    65         error_page   500 502 503 504  /50x.html;
    66         location = /50x.html {
    67             root   /usr/share/nginx/html;
    68         }
    69     }
    70 }
    挂载的配置文件
  4. 启动容器
    docker run -p 80:80 -p 443:443 --name mynginx  -v /home/nginx/config/nginx.conf:/etc/nginx/nginx.conf  -v /home/nginx/cert:/etc/nginx/cert:rw -d nginx
    启动指令
  5. FQ
    1.(iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 443 -j DNAT --to-destination 172.17.0.3:443 ! -i docker0: iptables: No chain/target/match by that name.
     (exit status 1))
      解决方案:
        systemctl restart docker
    遇到的问题


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM