Dockerfile.nginx 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. ###############################################################################
  2. # Build stage – compile OpenSSL 1.0.2u and nginx 1.28.0
  3. #
  4. # Why the ancient OpenSSL? AIM 6.2–7.0 begin the TLS handshake with an
  5. # SSLv2-format ("v2 hello") ClientHello for backward compatibility, even when
  6. # they go on to negotiate TLS 1.0. OpenSSL 1.1.0 removed the code that parses
  7. # these SSLv2-style ClientHello records, so any modern OpenSSL (1.1.x / 3.x)
  8. # rejects the handshake outright. OpenSSL 1.0.2u is the last release that still
  9. # accepts the v2 hello, so nginx must be linked against it to front these
  10. # clients.
  11. ###############################################################################
  12. FROM debian:12.11-slim AS build
  13. ARG OPENSSL_VERSION=1.0.2u
  14. ARG OPENSSL_TAG=OpenSSL_1_0_2u
  15. ARG NGINX_VERSION=1.28.0
  16. ARG OPENSSL_URL=https://github.com/openssl/openssl/releases/download/${OPENSSL_TAG}/openssl-${OPENSSL_VERSION}.tar.gz
  17. ARG NGINX_URL=https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz
  18. # Build prerequisites
  19. RUN apt-get update && \
  20. apt-get install -y --no-install-recommends \
  21. build-essential \
  22. ca-certificates \
  23. wget \
  24. perl \
  25. openssl \
  26. libpcre2-dev \
  27. zlib1g-dev && \
  28. rm -rf /var/lib/apt/lists/*
  29. WORKDIR /usr/src
  30. # ---------- OpenSSL ----------------------------------------------------------
  31. # Sources only. nginx's --with-openssl builds and statically links them itself,
  32. # so there is no shared library to ship or point LD_LIBRARY_PATH at.
  33. RUN wget -qO openssl.tar.gz "${OPENSSL_URL}" && \
  34. tar xzf openssl.tar.gz
  35. # ---------- nginx ------------------------------------------------------------
  36. # http serves the Kerberos and Web API backends, which are routed by path;
  37. # stream carries the OSCAR BOS listener as opaque TCP.
  38. RUN wget -qO nginx.tar.gz "${NGINX_URL}" && \
  39. tar xzf nginx.tar.gz && \
  40. cd nginx-${NGINX_VERSION} && \
  41. ./configure \
  42. --prefix=/etc/nginx \
  43. --sbin-path=/usr/local/sbin/nginx \
  44. --conf-path=/etc/nginx/nginx.conf \
  45. --pid-path=/var/run/nginx.pid \
  46. --lock-path=/var/run/nginx.lock \
  47. --error-log-path=/dev/stdout \
  48. --http-log-path=/dev/stdout \
  49. --http-client-body-temp-path=/var/cache/nginx/client_temp \
  50. --http-proxy-temp-path=/var/cache/nginx/proxy_temp \
  51. --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
  52. --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
  53. --http-scgi-temp-path=/var/cache/nginx/scgi_temp \
  54. --user=nobody \
  55. --group=nogroup \
  56. --with-http_ssl_module \
  57. --with-stream \
  58. --with-stream_ssl_module \
  59. --with-openssl=/usr/src/openssl-${OPENSSL_VERSION} && \
  60. make -j"$(nproc)" && \
  61. make install
  62. # DH parameters. nginx offers no DHE ciphers at all unless ssl_dhparam is set.
  63. RUN openssl dhparam -out /etc/nginx/dhparam.pem 2048
  64. ###############################################################################
  65. # Runtime stage – only what we need to run nginx
  66. ###############################################################################
  67. FROM debian:12.11-slim AS runtime
  68. RUN apt-get update && \
  69. apt-get install -y --no-install-recommends libpcre2-8-0 zlib1g && \
  70. rm -rf /var/lib/apt/lists/*
  71. COPY --from=build /usr/local/sbin/nginx /usr/local/sbin/nginx
  72. COPY --from=build /etc/nginx/dhparam.pem /etc/nginx/dhparam.pem
  73. COPY --from=build /etc/nginx/mime.types /etc/nginx/mime.types
  74. # Mount points for the user-supplied nginx.conf, server.pem and web client, plus the temp dirs the worker writes buffered bodies to.
  75. RUN mkdir -p /etc/nginx/certs /srv/client /var/run /var/cache/nginx && \
  76. chown nobody:nogroup /var/cache/nginx
  77. EXPOSE 80 443 5193
  78. ENTRYPOINT ["/usr/local/sbin/nginx", "-g", "daemon off;"]