構建帶headers-more-nginx-module的nginx

NAVYSUMMER發表於2024-09-19

Dockerfile

# 使用官方的 Alpine 基礎映象
FROM alpine:latest
ARG VERSION=1.24.0
# 更新包列表並安裝必要的依賴
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
RUN apk update && \
    apk add --no-cache build-base libgcc zlib-dev pcre-dev openssl-dev git

# 建立臨時目錄用於編譯 Nginx
RUN mkdir /tmp/nginx-src
WORKDIR /tmp/nginx-src

# 下載 Nginx 原始碼
RUN wget https://nginx.org/download/nginx-${VERSION}.tar.gz
RUN tar -xzvf nginx-${VERSION}.tar.gz
WORKDIR /tmp/nginx-src/nginx-${VERSION}

# 下載 headers-more 模組
RUN git clone https://github.com/openresty/headers-more-nginx-module.git

# 編譯 Nginx
RUN ./configure --prefix=/etc/nginx --add-module=/tmp/nginx-src/nginx-${VERSION}/headers-more-nginx-module 
RUN make
RUN make install

# 清理編譯環境
RUN rm -rf /tmp/nginx-src

# 複製自定義的 Nginx 配置檔案到容器中
COPY nginx.conf /etc/nginx/nginx.conf

# 啟動 Nginx
CMD ["nginx", "-g", "daemon off;"]

  

相關文章