docker+nginx+tomcat+https搭建

1、腾讯云申请SSL证书
2、下载证书及私钥文件

3、启动tomcat容器,映射webapps、logs

docker run --name tomcat-wz --rm -d -p 7001:8080 -v /data/projects/wz/webapps:/usr/local/tomcat/webapps -v /data/projects/wz/logs:/usr/local/tomcat/logs tomcat:7-jre8

4、启动nginx容器,指定证书、私钥、nginx.conf、logs,nginx.conf配置https相关以及tomcat转发

nginx.conf

worker_processes  1;
events {
  worker_connections  1024;
}
http {
  include       mime.types;
  default_type  application/octet-stream;
  sendfile        on;
  keepalive_timeout  65;
  log_format		main	'$remote_addr - $remote_user [$time_local] $request '
					'"$status" $body_bytes_sent "$http_referer" '
					'"$http_user_agent" "$http_x_forwarded_for" "$gzip_ratio"';
  server
    {
      listen 80;
      server_name dev.website.com;
      rewrite ^(.*) https://$host$1 permanent;
    }
  server{
      listen 443;
      server_name dev.website.com;

      ssl on;
      ssl_certificate /key/1_dev.website.com_bundle.crt;
      ssl_certificate_key /key/2_dev.website.com.key;
      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 / {
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://ip:7001/;
      }

      error_log    /logs/error_dev.log    error;
      access_log   /logs/access_dev.log    main;
  }
}
docker run --name nginx --rm -v /data/nginx/nginx.conf:/etc/nginx/nginx.conf -v /data/nginx/key:/key -v /data/nginx/logs:/logs -d -p 80:80 -p 443:443 -v /etc/localtime:/etc/localtime:ro -v /etc/timezone:/etc/timezone:ro ngin

docker命令注意别漏了443端口映射



你可能感兴趣的:(Docker,Linux使用,Java开发)