Dockerfile:
FROM nginxENV WORK_DIR /project
ENV GATEWAY_IP=127.0.0.1USER 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.confEXPOSE 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;\""]
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;}#病房网关 Websockerlocation /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};#}
}
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;#允许websocketmap $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;
}