• Dockerfile打包nginx镜像


    Dockerfile:

    FROM nginx
    
    ENV WORK_DIR /project
    ENV GATEWAY_IP=127.0.0.1
    
    USER root
    RUN mkdir ${WORK_DIR}
    
    #拷贝前端项目
    ADD chinaunicom-digitward-portal-web-view.tar.gz ${WORK_DIR}
    ADD mdt-view.tar.gz ${WORK_DIR}
    ADD unicom-cloud-medical-admin-view.tar.gz ${WORK_DIR}
    
    #拷贝nginx配置文件
    COPY nginx.conf /etc/nginx/nginx.conf
    COPY 80.conf /etc/nginx/conf.d/default.conf
    
    EXPOSE 80
    #将 default.conf 内的${GATEWAY_IP}替换为环境变量的值(K8s部署的时候后端的ip地址时不固定的,需要动态读取)
    CMD ["/bin/bash", "-c", "envsubst '${GATEWAY_IP}' < /etc/nginx/conf.d/default.conf > temp.conf; mv temp.conf /etc/nginx/conf.d/default.conf; nginx -g \"daemon off;\""]           
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    default.conf配置

    server {
        listen 80;
    
    # 统一规则的前端代理
        location ~ /.*-view {
            root /project;
            index index.html index.htm;
        }
    
    # 统一规则的前端代理
        location / {
         #访问根路径时跳转至 对应的路径   
         #$scheme读取请求的类型如:http,https 
         #$http_host 读取请求域名和端口
       	 return 301 $scheme://$http_host/web-view/#/login?UMSLogin=true&appUMSId=mdt;
       }
    
    #病房网关 Websocker
        location /digit_ward_gateway/.*/ws {
    	 proxy_set_header X-Real-IP $remote_addr;
       	 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       	 proxy_set_header Host $http_host;
       	 proxy_http_version 1.1;
       	 proxy_set_header Upgrade $http_upgrade;
        	 proxy_set_header Connection "upgrade";
    	 proxy_read_timeout 3600;
     	 proxy_pass http://${GATEWAY_IP}:7777/;
    }
    
    # 数字化病房网关服务
        location /digit_ward_gateway/ {
        proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
    
            proxy_set_header Host $proxy_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_pass http://${GATEWAY_IP}:7777/;
        }
    
       # location /browser/ {
       	#proxy_set_header   X-Forwarded-Proto $scheme;
    	#proxy_set_header   Host              $http_host;
    	#proxy_set_header   X-Real-IP         $remote_addr;
        	#proxy_pass  ${SW_COLLECTOR};
       #}
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49

    nginx.conf

    user  nginx;
    worker_processes  auto;
    
    error_log  /var/log/nginx/error.log notice;
    pid        /var/run/nginx.pid;
    
    
    events {
        worker_connections  1024;
    }
    
    
    http {
        include       /etc/nginx/mime.types;
        default_type  application/octet-stream;
        
        charset  utf-8;
        server_tokens off;
    
        #允许websocket
         map $http_upgrade $connection_upgrade {
               default         keep-alive;
               'websocket'     upgrade;
         }
    
    
        log_format  access_json  
            '{
                "@timestamp":"$time_iso8601",'
                '"@version":"1",'
                '"client":"$remote_addr",'
                '"url":"$uri",'
                '"status":"$status",'
                '"domain":"$host",'
                '"host":"$server_addr",'
                '"size":"$body_bytes_sent",'
                '"responsentime":"$request_time",'
                '"referer":"$http_referer",'
                '"useragent":"$http_user_agent",'
                '"upstreampstatus":"$upstream_status",'
                '"upstreamaddr":"$upstream_addr",'
                '"upstreamresponsetime":"$upstream_response_time"'
            '}';
    
        access_log  /var/log/nginx/access.log  access_json;
    
        keepalive_timeout 3600;
        send_timeout 300;
        sendfile        on;
        client_max_body_size 10G;
        client_body_buffer_size 2m;
        fastcgi_connect_timeout 1800;
        fastcgi_send_timeout    1800;
        fastcgi_read_timeout    1800;
        fastcgi_buffer_size 64k;
        fastcgi_buffers 8 128k;
        fastcgi_busy_buffers_size 128k;
        fastcgi_temp_file_write_size 128k;
        proxy_connect_timeout   3600;
        proxy_send_timeout      1800;
        proxy_read_timeout      1800;
        gzip on;
        gzip_min_length 1k;
        gzip_buffers 4 16k;
        gzip_http_version 1.1;
        gzip_comp_level 3;
        gzip_types text/plain application/json application/javascript application/x-javascript application/css application/xml application/xml+rss text/javascript application/x-httpd-php image/jpeg image/gif image/png image/x-ms-bmp application/wasm;
        gzip_vary off;
    
        include /etc/nginx/conf.d/*.conf;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
  • 相关阅读:
    【Linux环境安装教程】
    Newman
    第15章 - 垃圾回收相关算法
    AXURE RP EXTENSION For Chrome 安装
    EL表达式的内置对象及其作用域
    【使用Cpolar和Qchan搭建自己的个人图床】
    Redux(mvc、flux、react-redux)
    vue页面批量引入组件
    工厂人员违规行为识别系统
    数据结构(一) -- 队列
  • 原文地址:https://blog.csdn.net/dndndnnffj/article/details/132846214