nginx

关注公众号 jb51net

关闭
首页 > 网站技巧 > 服务器 > nginx > Dockerfile打包nginx镜像

Dockerfile打包nginx镜像的实现步骤

作者:爱码猿

本文主要介绍了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;\""]           

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};
   #}
}

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

到此这篇关于Dockerfile打包nginx镜像的实现步骤的文章就介绍到这了,更多相关Dockerfile打包nginx镜像内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家! 

您可能感兴趣的文章:
阅读全文