Dockerfile打包nginx鏡像的實(shí)現(xiàn)步驟
Dockerfile:
FROM nginx
ENV WORK_DIR /project
ENV GATEWAY_IP=127.0.0.1
USER root
RUN mkdir ${WORK_DIR}
#拷貝前端項(xiàng)目
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 內(nèi)的${GATEWAY_IP}替換為環(huán)境變量的值(K8s部署的時(shí)候后端的ip地址時(shí)不固定的,需要?jiǎng)討B(tài)讀取)
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;
# 統(tǒng)一規(guī)則的前端代理
location ~ /.*-view {
root /project;
index index.html index.htm;
}
# 統(tǒng)一規(guī)則的前端代理
location / {
#訪問(wèn)根路徑時(shí)跳轉(zhuǎn)至 對(duì)應(yīng)的路徑
#$scheme讀取請(qǐng)求的類型如:http,https
#$http_host 讀取請(qǐng)求域名和端口
return 301 $scheme://$http_host/web-view/#/login?UMSLogin=true&appUMSId=mdt;
}
#病房網(wǎng)關(guān) 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/;
}
# 數(shù)字化病房網(wǎng)關(guān)服務(wù)
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;
}到此這篇關(guān)于Dockerfile打包nginx鏡像的實(shí)現(xiàn)步驟的文章就介紹到這了,更多相關(guān)Dockerfile打包nginx鏡像內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Linux Nginx下SSL證書(shū)安裝方法及WordPress CDN配置
這篇文章主要介紹了Linux Nginx下SSL證書(shū)安裝方法及WordPress CDN配置,需要的朋友可以參考下2017-08-08
Nginx中try_files指令的實(shí)現(xiàn)示例
try_files是Nginx配置中的一個(gè)指令,用于檢查文件是否存在,并根據(jù)存在情況處理請(qǐng)求,本文就來(lái)介紹一下Nginx中try_files指令的實(shí)現(xiàn)示例,感興趣的可以了解一下2024-10-10
Nginx配置同時(shí)支持http和https的兩種方式
現(xiàn)在的網(wǎng)站支持Https幾乎是標(biāo)配功能,Nginx能很好的支持Https功能,本文主要介紹了Nginx配置同時(shí)支持http和https的兩種方式,具有一定的參考價(jià)值,感興趣的可以了解一下2024-03-03
Nginx?504?Gateway?Time-out的兩種最新解決方案
大家在訪問(wèn)網(wǎng)站的時(shí)候通常會(huì)遇到502錯(cuò)誤、404錯(cuò)誤等,很少會(huì)遇到504錯(cuò)誤,但是在我們?nèi)ピL問(wèn)大流量或者內(nèi)容數(shù)據(jù)量較多的網(wǎng)站時(shí),打開(kāi)網(wǎng)頁(yè)偶爾就會(huì)出現(xiàn)504 gateway time-out,這篇文章主要給大家介紹了關(guān)于Nginx?504?Gateway?Time-out的兩種解決方案,需要的朋友可以參考下2022-08-08
Nginx 502 Bad Gateway錯(cuò)誤常見(jiàn)的4種原因和解決方法
這篇文章主要介紹了Nginx 502 Bad Gateway錯(cuò)誤常見(jiàn)的4種原因和解決方法,本文適用FastCGI環(huán)境,其中多數(shù)原因通過(guò)配置相關(guān)參數(shù)即可解決,需要的朋友可以參考下2015-05-05
配置nginx 重定向到系統(tǒng)維護(hù)頁(yè)面
今天抽時(shí)間給大家普及nginx 重定向到系統(tǒng)維護(hù)頁(yè)面的配置內(nèi)容,nginx重定向問(wèn)題說(shuō)起來(lái)也很簡(jiǎn)單,因?yàn)橹囟ㄏ蚝笾苯犹D(zhuǎn)到靜態(tài)頁(yè)面,不需要后續(xù)操作和記錄,所以直接301永久重定向。今天簡(jiǎn)單給大家介紹配置方法,一起看看吧2021-06-06

