Dockerfile打包nginx镜像的实现步骤

 更新时间:2023年10月24日 11:37:49   作者:爱码猿  
本文主要介绍了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镜像内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家! 

相关文章

  • 基于nginx access日志格式详解

    基于nginx access日志格式详解

    下面小编就为大家分享一篇基于nginx access日志格式详解,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2018-03-03
  • Linux Nginx下SSL证书安装方法及WordPress CDN配置

    Linux Nginx下SSL证书安装方法及WordPress CDN配置

    这篇文章主要介绍了Linux Nginx下SSL证书安装方法及WordPress CDN配置,需要的朋友可以参考下
    2017-08-08
  • Nginx中try_files指令的实现示例

    Nginx中try_files指令的实现示例

    try_files是Nginx配置中的一个指令,用于检查文件是否存在,并根据存在情况处理请求,本文就来介绍一下Nginx中try_files指令的实现示例,感兴趣的可以了解一下
    2024-10-10
  • Nginx配置同时支持http和https的两种方式

    Nginx配置同时支持http和https的两种方式

    现在的网站支持Https几乎是标配功能,Nginx能很好的支持Https功能,本文主要介绍了Nginx配置同时支持http和https的两种方式,具有一定的参考价值,感兴趣的可以了解一下
    2024-03-03
  • Nginx生成缩略图并存储到硬盘上

    Nginx生成缩略图并存储到硬盘上

    这篇文章主要介绍了Nginx生成缩略图并存储到硬盘上的相关资料,需要的朋友可以参考下
    2016-03-03
  • Nginx 504 Gateway Time-out的两种最新解决方案

    Nginx 504 Gateway Time-out的两种最新解决方案

    大家在访问网站的时候通常会遇到502错误、404错误等,很少会遇到504错误,但是在我们去访问大流量或者内容数据量较多的网站时,打开网页偶尔就会出现504 gateway time-out,这篇文章主要给大家介绍了关于Nginx 504 Gateway Time-out的两种解决方案,需要的朋友可以参考下
    2022-08-08
  • 详解nginx日志定时备份和删除

    详解nginx日志定时备份和删除

    本篇文章主要介绍了nginx日志定时备份和删除 ,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-06-06
  • 详解如何修改nginx的默认端口

    详解如何修改nginx的默认端口

    这篇文章主要介绍了详解如何修改nginx的默认端口,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2021-03-03
  • Nginx 502 Bad Gateway错误常见的4种原因和解决方法

    Nginx 502 Bad Gateway错误常见的4种原因和解决方法

    这篇文章主要介绍了Nginx 502 Bad Gateway错误常见的4种原因和解决方法,本文适用FastCGI环境,其中多数原因通过配置相关参数即可解决,需要的朋友可以参考下
    2015-05-05
  • 配置nginx 重定向到系统维护页面

    配置nginx 重定向到系统维护页面

    今天抽时间给大家普及nginx 重定向到系统维护页面的配置内容,nginx重定向问题说起来也很简单,因为重定向后直接跳转到静态页面,不需要后续操作和记录,所以直接301永久重定向。今天简单给大家介绍配置方法,一起看看吧
    2021-06-06

最新评论