千家信息网

可根据配置文件变化自动reload的openresty docker镜像制作

发表于:2026-11-02 作者:千家信息网编辑
千家信息网最后更新 2026年11月02日,1. 创建工作目录mkdir openresty && cd openresty2. 编写使用inotify监控配置文件变化并自动reload的脚本auto-reload.sh:#!/bin/shin
千家信息网最后更新 2026年11月02日可根据配置文件变化自动reload的openresty docker镜像制作

1. 创建工作目录

mkdir openresty && cd openresty

2. 编写使用inotify监控配置文件变化并自动reload的脚本auto-reload.sh:

#!/bin/shinotifywait -e modify,move,create,delete -mr --timefmt '%d/%m/%y %H:%M' --format '%T %f %e' \/usr/local/openresty/nginx/conf/conf.d | while read event; do    echo "$event"    /usr/local/openresty/nginx/sbin/nginx -s reloaddone

3. 编写镜像启动脚本start.sh:

#!/bin/bash/usr/bin/openresty -g "daemon off;" &/auto-reload.sh

4. 编写配置文件nginx.conf:

user nobody;worker_processes  auto;#worker_cpu_affinity 01 10;worker_rlimit_nofile 65535;events {    use epoll;    worker_connections  60000;}http {    include       mime.types;    default_type  application/octet-stream;    tcp_nodelay   on;    log_format  main  '$status $host $remote_addr $request_time - '                      '$upstream_status $upstream_addr $upstream_response_time '                      '[$time_local] $request '                      '$bytes_sent $body_bytes_sent "$http_referer" '                      '"$http_user_agent" "$http_x_forwarded_for"';    access_log /usr/local/openresty/nginx/logs/access.log main;    error_log /usr/local/openresty/nginx/logs/error.log;    log_not_found  off;    sendfile        on;    keepalive_timeout  15;    server_names_hash_bucket_size 4096;    client_header_buffer_size 16k;    large_client_header_buffers 4 64k;    gzip on;    gzip_http_version 1.0;    gzip_proxied     expired no-cache no-store private auth;    gzip_types       text/plain application/x-javascript text/css  application/xml text/javascript;    gzip_min_length  1000;    gzip_comp_level 5;    gzip_buffers    4 8k;    gzip_disable "MSIE [1-6]\.(?!.*SV1)";    include localenv.d/*.conf;    include env.d/*.conf;    include conf.d/*.backend.cfg;    include conf.d/*.server.cfg;    server {        listen       80;        server_name  localhost;        #access_log  logs/host.access.log  main;        location / {            root   html;            index  index.html index.htm;        }        #error_page  404              /404.html;        # redirect server error pages to the static page /50x.html        #        error_page   500 502 503 504  /50x.html;        location = /50x.html {            root   html;        }    }}

5. 编写dockerfile:

FROM centos:7.6.1810 MAINTAINER openresty1.15.8.2  ADD auto-reload.sh auto-reload.shADD start.sh start.shRUN yum -y install epel-release && yum install inotify-tools -y && yum install -y yum-utils && yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo && yum install -y openresty && yum clean all && chmod +x start.sh && chmod +x auto-reload.shADD nginx.conf /usr/local/openresty/nginx/conf/nginx.confEXPOSE 80EXPOSE 443CMD ["./start.sh"]

6. 执行docker build命令:

docker build -t openresty:1.15.8.2 -f ./dockerfile .

上述命令执行完后,就可以通过docker images看到刚制作好的openresty镜像了

7. 验证,用以下命令运行容器:

docker run -itd -p 8080:80 -v /data/logs:/usr/local/openresty/nginx/logs -v /data/nginx/conf.d:/usr/local/openresty/nginx/conf/conf.d openresty:1.15.8.2

在宿主机目录/data/nginx/conf.d下新增或修改配置文件,容器中的openresty会自动reload,镜像制作成功。


文件 镜像 配置 命令 制作 容器 目录 脚本 变化 成功 可以通过 宿主 宿主机 用以 工作 监控 运行 验证 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 上海挚品互联网科技有限公司 上海卓越科技互联网 互联网科技工作委员会副主任毛军 互联网与科技金融数据 亿策互联网科技 顺网科技2021年互联网排名 科技赋能互联网健康 互联网汽车科技小镇 互联网科技项目计划书材料类 中国科技创新与世界互联网大会 翼展科技 首家互联网医院 中国互联网有什么科技 银行科技岗属于互联网吗 产业互联网科技服务公司 半导体行业属于互联网高科技类吗 福州德业互联网科技 求路客互联网科技电话 科技互联网经济论坛 互联网的科技体现在哪里 如何强化互联网金融科技 保险科技 互联网保险 科技互联网项目 小米互联网科技园设置 随着互联网科技发展 北京华百购互联网科技有限公司 现代互联网科技股 和信科技工业互联网 知域互联网科技有限公司大骗子 济南小医互联网科技有限公司招聘 福建互联网展示科技馆设计
0