Skip to content

Instantly share code, notes, and snippets.

@mahdilamb
Last active January 13, 2026 23:16
Show Gist options
  • Select an option

  • Save mahdilamb/c31ff579a05eff57a196c4d89cf82f52 to your computer and use it in GitHub Desktop.

Select an option

Save mahdilamb/c31ff579a05eff57a196c4d89cf82f52 to your computer and use it in GitHub Desktop.
Dockerfile for routing https traffic to http
FROM alpine:latest AS cert-init
RUN apk add openssl
WORKDIR /root/ssl
RUN openssl req -x509 -nodes -newkey rsa:2048 \
-keyout key.pem \
-out cert.pem \
-days 365 \
-sha256 \
-subj "/CN=localhost" \
-addext "subjectAltName=DNS:localhost,IP:127.0.0.1"
FROM nginx:latest
ARG TARGET=http://localhost:8000/
ENV TARGET=${TARGET}
COPY --from=cert-init /root/ssl /root/ssl
RUN cat <<EOF > /etc/nginx/conf.d/default.conf
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name localhost;
ssl_certificate /root/ssl/cert.pem;
ssl_certificate_key /root/ssl/key.pem;
location / {
proxy_pass "${TARGET}";
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host \$host;
}
}
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment