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

Release 1.0 beta2 #54

Merged
merged 8 commits into from
Dec 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Dockerfiles/Dockerfile.alpine
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ LABEL \
###
### Build arguments
###
ARG VHOST_GEN_GIT_REF=1.0.8
ARG VHOST_GEN_GIT_REF=1.0.9
ARG WATCHERD_GIT_REF=v1.0.7
ARG CERT_GEN_GIT_REF=0.10
ARG ARCH=linux/amd64
Expand Down Expand Up @@ -66,7 +66,7 @@ RUN set -eux \
&& rm -rf mod-proxy-fcgi* \
\
# Install vhost-gen
&& wget --no-check-certificate -O vhost-gen.tar.gz "https://github.com/devilbox/vhost-gen/archive/refs/tags/${VHOST_GEN_GIT_REF}.tar.gz" \
&& wget --no-check-certificate -O vhost-gen.tar.gz "https://github.com/devilbox/vhost-gen/archive/${VHOST_GEN_GIT_REF}.tar.gz" \
&& tar xvfz vhost-gen.tar.gz \
&& cd "vhost-gen-${VHOST_GEN_GIT_REF}" \
&& make install \
Expand Down Expand Up @@ -124,7 +124,7 @@ RUN set -eux \
ENV MY_USER=daemon
ENV MY_GROUP=daemon
ENV HTTPD_START="httpd-foreground"
ENV HTTPD_RELOAD="/usr/local/apache2/bin/httpd -k stop"
ENV HTTPD_RELOAD="/usr/local/apache2/bin/httpd -k restart"
ENV HTTPD_VERSION="httpd -V 2>&1 | head -1 | awk '{print \$3}'"
ENV VHOSTGEN_HTTPD_SERVER="apache22"

Expand Down
6 changes: 3 additions & 3 deletions Dockerfiles/Dockerfile.debian
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ LABEL \
###
### Build arguments
###
ARG VHOST_GEN_GIT_REF=1.0.8
ARG VHOST_GEN_GIT_REF=1.0.9
ARG WATCHERD_GIT_REF=v1.0.7
ARG CERT_GEN_GIT_REF=0.10
ARG ARCH=linux/amd64
Expand Down Expand Up @@ -61,7 +61,7 @@ RUN set -eux \
&& rm -rf mod-proxy-fcgi* \
\
# Install vhost-gen
&& wget --no-check-certificate -O vhost-gen.tar.gz "https://github.com/devilbox/vhost-gen/archive/refs/tags/${VHOST_GEN_GIT_REF}.tar.gz" \
&& wget --no-check-certificate -O vhost-gen.tar.gz "https://github.com/devilbox/vhost-gen/archive/${VHOST_GEN_GIT_REF}.tar.gz" \
&& tar xvfz vhost-gen.tar.gz \
&& cd "vhost-gen-${VHOST_GEN_GIT_REF}" \
&& make install \
Expand Down Expand Up @@ -120,7 +120,7 @@ RUN set -eux \
ENV MY_USER=daemon
ENV MY_GROUP=daemon
ENV HTTPD_START="httpd-foreground"
ENV HTTPD_RELOAD="/usr/local/apache2/bin/httpd -k stop"
ENV HTTPD_RELOAD="/usr/local/apache2/bin/httpd -k restart"
ENV HTTPD_VERSION="httpd -V 2>&1 | head -1 | awk '{print \$3}'"
ENV VHOSTGEN_HTTPD_SERVER="apache22"

Expand Down
41 changes: 35 additions & 6 deletions Dockerfiles/data/docker-entrypoint.d/.httpd/func-backend.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ set -o pipefail
### conf:phpfpm:tcp:<host>:<port> # Remote PHP-FPM server at <host>:<port>
### conf:rproxy:http:<host>:<port> # Reverse Proxy server at http://<host>:<port>
### conf:rproxy:https:<host>:<port> # Reverse Proxy server at https://<host>:<port>
### conf:rproxy:ws:<host>:<port> # Reverse Proxy (websocket) at ws://<host>:<port>
### conf:rproxy:wss:<host>:<port> # Reverse Proxy (websocket) at wss://<host>:<port>
###
###
### Format-2: file:<file>
Expand All @@ -40,6 +42,8 @@ set -o pipefail
### Examples:
### conf:rproxy:http:10.0.0.1:3000
### conf:rproxy:https:mydomain.com:8080
### conf:rproxy:ws:10.0.0.1:3000
### conf:rproxy:wss:10.0.0.1:3000
###
### Note: If no file is found, a warning will be logged and no Reverse proxy will be created.
###
Expand Down Expand Up @@ -90,7 +94,13 @@ backend_conf_is_valid() {
fi
# 3. Protocol: 'tcp', 'http' or 'https'
if ! backend_is_valid_conf_prot "${1}"; then
echo "Invalid backend conf:<prot> in: '${1}'. It must be 'tcp', 'http' or 'https'"
# Apache 2.2 does not have websocket support
if [ "${VHOSTGEN_HTTPD_SERVER}" = "apache22" ]; then
echo "Invalid backend conf:<prot> in: '${1}'. It must be 'tcp', 'http' or 'https'."
# All other webserver have websocket support
else
echo "Invalid backend conf:<prot> in: '${1}'. It must be 'tcp', 'http', 'https', 'ws' or 'wss'."
fi
return 1
fi
# 4. Host
Expand All @@ -116,9 +126,22 @@ backend_conf_is_valid() {
fi
# 7. Validate conf <protocol> rproxy == http(s)?
if [ "${backend_conf_type}" = "rproxy" ]; then
if [ "${backend_conf_prot}" != "http" ] && [ "${backend_conf_prot}" != "https" ]; then
echo "Invalid backend conf:<prot> in: '${1}'. 'rproxy' only supports 'http' or 'https'"
return 1
# Apache 2.2 does not have websocket support
if [ "${VHOSTGEN_HTTPD_SERVER}" = "apache22" ]; then
if [ "${backend_conf_prot}" != "http" ] \
&& [ "${backend_conf_prot}" != "https" ]; then
echo "Invalid backend conf:<prot> in: '${1}'. 'rproxy' only supports 'http' and 'https'"
return 1
fi
# All other webserver have websocket support
else
if [ "${backend_conf_prot}" != "http" ] \
&& [ "${backend_conf_prot}" != "https" ] \
&& [ "${backend_conf_prot}" != "ws" ] \
&& [ "${backend_conf_prot}" != "wss" ]; then
echo "Invalid backend conf:<prot> in: '${1}'. 'rproxy' only supports 'http', 'https', 'ws' and 'wss'"
return 1
fi
fi
fi
}
Expand Down Expand Up @@ -181,8 +204,14 @@ backend_is_valid_conf_prot() {
local value
value="$( get_backend_conf_prot "${1}" )"

if [ "${value}" != "tcp" ] && [ "${value}" != "http" ] && [ "${value}" != "https" ]; then
return 1
if [ "${VHOSTGEN_HTTPD_SERVER}" = "apache22" ];then
if [ "${value}" != "tcp" ] && [ "${value}" != "http" ] && [ "${value}" != "https" ]; then
return 1
fi
else
if [ "${value}" != "tcp" ] && [ "${value}" != "http" ] && [ "${value}" != "https" ] && [ "${value}" != "ws" ] && [ "${value}" != "wss" ]; then
return 1
fi
fi
return 0
}
Expand Down
37 changes: 27 additions & 10 deletions Dockerfiles/data/docker-entrypoint.d/02-env-vars-validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,12 @@ _validate_vhost_backend() {
# 5. Validate conf <protocol>
if ! backend_is_valid_conf_prot "${value}"; then
_log_env_valid "invalid" "${name}" "${value}" "Invalid format"
_log_env_valid "invalid" "${name}" "${backend_conf_prot}" "<proto> is invalid. Must be: " "'tcp', 'http' or 'https'"
# Apache 2.2 does not have websocket support
if [ "${VHOSTGEN_HTTPD_SERVER}" = "apache22" ];then
_log_env_valid "invalid" "${name}" "${backend_conf_prot}" "<proto> is invalid. Must be: " "'tcp', 'http' or 'https'"
else
_log_env_valid "invalid" "${name}" "${backend_conf_prot}" "<proto> is invalid. Must be: " "'tcp', 'http', 'https', 'ws' or 'wss'"
fi
_log_backend_examples "conf"
exit 1
fi
Expand All @@ -662,11 +667,21 @@ _validate_vhost_backend() {
fi
# 7. Validate conf <protocol> rproxy == http(s)?
if [ "${backend_conf_type}" = "rproxy" ]; then
if [ "${backend_conf_prot}" != "http" ] && [ "${backend_conf_prot}" != "https" ]; then
_log_env_valid "invalid" "${name}" "${value}" "Invalid format"
_log_env_valid "invalid" "${name}" "${backend_conf_prot}" "rproxy only supports protocol " "'http' or 'https'"
_log_backend_examples "conf"
exit 1
# Apache 2.2 does not have websocket support
if [ "${VHOSTGEN_HTTPD_SERVER}" = "apache22" ];then
if [ "${backend_conf_prot}" != "http" ] && [ "${backend_conf_prot}" != "https" ]; then
_log_env_valid "invalid" "${name}" "${value}" "Invalid format"
_log_env_valid "invalid" "${name}" "${backend_conf_prot}" "rproxy only supports protocol " "'http' and 'https'"
_log_backend_examples "conf"
exit 1
fi
else
if [ "${backend_conf_prot}" != "http" ] && [ "${backend_conf_prot}" != "https" ] && [ "${backend_conf_prot}" != "ws" ] && [ "${backend_conf_prot}" != "wss" ]; then
_log_env_valid "invalid" "${name}" "${value}" "Invalid format"
_log_env_valid "invalid" "${name}" "${backend_conf_prot}" "rproxy only supports protocol " "'http', 'https', 'ws' and 'wss'"
_log_backend_examples "conf"
exit 1
fi
fi
fi
# 8. Validate conf <host>
Expand Down Expand Up @@ -1062,11 +1077,13 @@ _log_backend_examples() {
log "err" "Example: conf:phpfpm:tcp:10.0.0.100:9000"
log "err" "Example: conf:phpfpm:tcp:domain.com:9000"
log "err" ""
log "err" "Example: conf:rproxy:http:10.0.0.100:3000"
log "err" "Example: conf:rproxy:http:domain.com:443"
log "err" ""
log "err" "Example: conf:rproxy:https:10.0.0.100:8080"
log "err" "Example: conf:rproxy:http:10.0.0.100:8080"
log "err" "Example: conf:rproxy:https:domain.com:8443"
if [ "${VHOSTGEN_HTTPD_SERVER}" != "apache22" ]; then
log "err" ""
log "err" "Example: conf:rproxy:ws:10.0.0.100:8080"
log "err" "Example: conf:rproxy:wss:domain.com:8443"
fi
fi
if [ "${show}" = "all" ] || [ "${show}" = "file" ]; then
log "err" ""
Expand Down
2 changes: 1 addition & 1 deletion Dockerfiles/data/nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ http {

# [emerg] could not build server_names_hash, you should increase server_names_hash_bucket_size: 32
# https://stackoverflow.com/questions/26357487/
server_names_hash_bucket_size 64;
server_names_hash_bucket_size 128;


# -------------------------------------------------------------------------------
Expand Down
27 changes: 23 additions & 4 deletions Dockerfiles/data/vhost-gen/templates-main/nginx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,31 @@ vhost_type:
root "__DOCUMENT_ROOT__";
index __INDEX__;

# Reverse Proxy (-r)
# Reverse Proxy (-r http(s)://ADDR:PORT)
rproxy: |
# Define the vhost to reverse proxy
# Define Reverse Proxy
location __LOCATION__ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
# https://stackoverflow.com/a/72586833
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# Proxy connection
proxy_pass __PROXY_PROTO__://__PROXY_ADDR__:__PROXY_PORT__;
}

# Reverse Proxy with websocket support (-r ws(s)://ADDR:PORT)
rproxy_ws: |
# Define Reverse Proxy with Websock support
location __LOCATION__ {
# https://stackoverflow.com/a/72586833
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# Websocket settings
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
# Proxy connection
proxy_pass __PROXY_PROTO__://__PROXY_ADDR__:__PROXY_PORT__;
}

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

This image is based on the official **[Apache 2.2](https://hub.docker.com/_/httpd)** Docker image and extends it with the ability to have **virtual hosts created automatically**, as well as **adding SSL certificates** when creating new directories. For that to work, it integrates two tools that will take care about the whole process: **[watcherd](https://github.com/devilbox/watcherd)** and **[vhost-gen](https://github.com/devilbox/vhost-gen)**.

From a users perspective, you mount your local project directory into the container under `/shared/httpd`. Any directory then created in your local project directory wil spawn a new virtual host by the same name. Each virtual host optionally supports a generic or custom backend configuration (**static files**, **PHP-FPM** or **reverse proxy**).
From a users perspective, you mount your local project directory into the container under `/shared/httpd`. Any directory then created in your local project directory wil spawn a new virtual host by the same name. Each virtual host optionally supports a generic or custom backend configuration: **static files**, **PHP-FPM** or **reverse proxy**.

For convenience the entrypoint script during `docker run` provides a pretty decent **validation and documentation** about wrong user input and suggests steps to fix it.

Expand Down
Loading