docker(nginx和tomcat)

docker(nginx和tomcat)

# 拉取镜像
docker pull nginx:1.19.0

# 编辑nginx.conf
vim /usr/local/serverFolder/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;
}


# 编辑default.conf
vim /usr/local/serverFolder/nginx/conf.d/default.conf

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


# 启动
docker run --name cxynginx -d -p 80:80  -v /usr/local/serverFolder/nginx/html:/usr/share/nginx/html -v /usr/local/serverFolder/nginx/conf/nginx.conf:/etc/nginx/nginx.conf  -v /usr/local/serverFolder/nginx/logs:/var/log/nginx -v /usr/local/serverFolder/nginx/conf.d:/etc/nginx/conf.d nginx:1.19.0

域名

# 配置域名,前后不分离。
server {
	    listen 80;
	    server_name bk.cuixiaoyan.xyz www.bk.cuixiaoyan.xyz;
	    
	    # listen 443 ssl;
		  # ssl off;
		  # ssl_certificate ../cert/zhzq1.pem;
		  # ssl_certificate_key ../cert/zhzq1.key;
		  # 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 / {
	    	   proxy_pass http://127.0.0.1:888/;
	        proxy_set_header HOST $host;
	        proxy_set_header X-Forwarded-Proto $scheme;
	        proxy_set_header X-Real-IP $remote_addr;
	        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	    }
	    error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
	}
	
# 配置域名,前后分离。
    server {
        listen 80;
        server_name cuixiaoyan.xyz www.cuixiaoyan.xyz;
	   
       listen 443 ssl;
        ssl off;
        ssl_certificate ../cert/zhzq.pem;
        ssl_certificate_key ../cert/zhzq.key;
        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;
	gzip on;
    gzip_min_length 1k;
    gzip_comp_level 9;
    gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
    gzip_vary on;
    gzip_disable "MSIE [1-6]\.";
        location ^~ /jeecg-boot {
            proxy_pass              http://127.0.0.1:8080/jeecg-boot/;
            proxy_set_header        Host 127.0.0.1;
            proxy_set_header        X-Real-IP $remote_addr;
            proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        }
        location / {
            root   html;
            index  index.html index.htm;
	    if (!-e $request_filename) {
                rewrite ^(.*)$ /index.html?s=$1 last;
                break;
            }
    }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

tomcat

# 拉取镜像
docker pull tomcat:9.0
# 启动并挂载
docker run -d --name=cxytomcat9 -v /usr/local/serverFolder/tomcat9/webapps:/usr/local/tomcat/webapps --privileged=true -p 8080:8080 tomcat:9.0
# 首页设置
# 进入容器
docker exec -it 容器id /bin/bash
# 将webapps.dist下拷贝到webapps下
cp -r webapps.dist/* webapps

image-20200628142022006