Skip to content

Instantly share code, notes, and snippets.

@davidwtbuxton
Created April 24, 2025 08:18
Show Gist options
  • Select an option

  • Save davidwtbuxton/746b4c919097072527e816dacb094e4e to your computer and use it in GitHub Desktop.

Select an option

Save davidwtbuxton/746b4c919097072527e816dacb094e4e to your computer and use it in GitHub Desktop.

Revisions

  1. davidwtbuxton created this gist Apr 24, 2025.
    16 changes: 16 additions & 0 deletions compose.yaml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    # Nginx will listen on localhost:8080, serving static assets and doing gzip compression.
    services:

    app:
    image: python:3.13-alpine
    ports: ["8000:8000"]
    command: ["python", "-m", "http.server"]

    nginx:
    build:
    dockerfile: nginx.dockerfile
    ports: ["8080:8080"]
    environment:
    PORT: "8080"
    APP_PORT: "8000"
    APP_HOST: "app"
    32 changes: 32 additions & 0 deletions nginx-default.conf.template
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    # Nginx server configuration.
    server {
    listen ${PORT};
    gzip on;
    gzip_types
    application/atom+xml
    application/javascript
    application/json
    application/rss+xml
    application/vnd.ms-excel
    application/xml
    image/svg+xml
    image/jpeg
    image/gif
    image/png
    image/webp
    text/css
    text/html
    text/plain
    text/xml
    ;

    location / {
    root /usr/share/nginx/html;
    index index.html;
    try_files $uri $uri/ @app;
    }

    location @app {
    proxy_pass http://${APP_HOST}:${APP_PORT};
    }
    }
    12 changes: 12 additions & 0 deletions nginx.dockerfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    # A custom nginx image including our static assets. This (mostly) works when running
    # in Cloud Run, with $PORT usually provided as "8000", but with sidecar containers
    # listening on 127.0.0.1 (which is different to Docker compose, where services have
    # their own service name on a shared network).
    FROM nginx:1.28-alpine

    ENV APP_PORT=8000
    ENV APP_HOST=127.0.0.1
    ENV PORT=80
    RUN rm /usr/share/nginx/html/index.html
    COPY nginx-default.conf.template /etc/nginx/templates/default.conf.template
    COPY static /usr/share/nginx/html/