Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental: migrate frontend webserver to Caddy #192

Closed
wants to merge 8 commits into from
19 changes: 9 additions & 10 deletions Containerfile-frontend
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,16 @@ RUN apk add --no-cache \
# Install system dependencies
RUN apk update && \
apk add --no-cache \
nginx
caddy

# Configure directory permissions
RUN chown -R nginx /var/log/nginx && \
rm -rf /var/www/localhost && \
chown nginx /var/www
RUN mkdir /var/www && \
chown caddy /var/www

COPY static/frontend/nginx.conf /etc/nginx/nginx.conf
COPY static/frontend/common.conf /etc/nginx/common.conf
COPY static/frontend/conf.d/default.conf /etc/nginx/conf.d/default.conf
COPY static/frontend/Caddyfile /etc/caddy/Caddyfile

# Install application dependencies (unprivileged)
USER nginx
USER caddy
WORKDIR /var/www

# Extract application release package
Expand All @@ -51,8 +48,10 @@ RUN apk del \
wget \
yarn

VOLUME ["/var/lib/caddy"]

EXPOSE 8080

USER nginx
USER caddy

CMD ["nginx", "-g", "daemon off;"]
CMD ["caddy", "run", "--config", "/etc/caddy/Caddyfile"]
30 changes: 30 additions & 0 deletions static/frontend/Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
admin off
http_port 8080
https_port 8443

# Do not add the webserver's local certificate authority to the container's trust store
skip_install_trust
}

localhost {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Todo: to make this configuration suitable for use with arbitarily-chosen domain names, this server address should be updated to expand from an environment variable.

That environment variable should have a default value of localhost specified in the Containerfile.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good point.

# Issue self-signed certificates on-demand from local certificate authority
tls {
issuer internal
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Todo: this certificate issuer configuration will require updates if/when this configuration is used in combination with public ACME CA servers.

on_demand
}

# Serve static file content
file_server
root * /var/www/public

# Fallback to PHP handling for missing files
try_files {path} /index.php?{query}

# Proxy PHP requests to the backend service
@php path *.php
php_fastcgi @php backend:9000

# Enable gzip compression
encode gzip
}