Author SHA1 Message Date
metas-jb 2de8ab305b refactor(webui): replace apache with nginx reverse proxy
Serve the static frontend and reverse-proxy the api paths to webapi and
app from an nginx:stable image instead of the EOL apache/ubuntu-16.04
build. TLS terminates at the host proxy and the container runs plain
HTTP; an optional SSL server activates when certs are mounted.
2026-09-09 16:15:21 +02:00
9 changed files with 166 additions and 278 deletions
+19 -23
View File
@@ -1,28 +1,24 @@
ARG BASE_REGISTRY=metasfresh
FROM $BASE_REGISTRY/metasfresh-webui:5.175
ARG MF_VERSION=5.175
COPY sources/configs/config.js /opt/metasfresh-webui-frontend/dist/
FROM ${BASE_REGISTRY}/metasfresh-webui:${MF_VERSION} AS bundle
# nginx:stable (Debian, not alpine) for GNU sed in the entrypoint.
FROM nginx:stable
RUN rm -f /etc/nginx/conf.d/default.conf
# openssl is used by the entrypoint to validate mounted certs.
RUN apt-get update \
&& apt-get install -y --no-install-recommends openssl \
&& rm -rf /var/lib/apt/lists/*
COPY conf.d/ /etc/nginx/conf.d/
COPY snippets/ /etc/nginx/snippets/
COPY docker-entrypoint.d/10-metasfresh.sh /docker-entrypoint.d/10-metasfresh.sh
RUN chmod +x /docker-entrypoint.d/10-metasfresh.sh
COPY --from=bundle /opt/metasfresh-webui-frontend/dist/ /opt/metasfresh-webui-frontend/dist/
COPY sources/configs/config.js /opt/metasfresh-webui-frontend/dist/
COPY sources/configs/mobile/config.js /opt/metasfresh-webui-frontend/dist/mobile/
#add apache config
COPY sources/configs/metasfresh_webui.conf /etc/apache2/sites-available/
RUN mkdir -p /etc/apache2/certs/
COPY sources/certs /etc/apache2/certs
RUN a2ensite metasfresh_webui.conf
#set environment
RUN . /etc/apache2/envvars
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_PID_FILE /var/run/apache2.pid
ENV APACHE_RUN_DIR /var/run/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
ENV APACHE_LOG_DIR /var/log/apache2
RUN chown www-data:www-data -R /opt/metasfresh-webui-frontend/
EXPOSE 80 443
ENTRYPOINT ["/start_webui.sh"]
+11
View File
@@ -0,0 +1,11 @@
# WebSocket upgrade map.
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
# Preserve X-Forwarded-Proto from the host proxy, fall back to $scheme.
map $http_x_forwarded_proto $forwarded_proto {
default $http_x_forwarded_proto;
'' $scheme;
}
+11
View File
@@ -0,0 +1,11 @@
# Enabled by the entrypoint (renamed to webui-ssl.conf) only when certs are mounted.
server {
listen 443 ssl;
server_name _;
ssl_certificate /etc/nginx/certs/fullchain.pem;
ssl_certificate_key /etc/nginx/certs/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
include /etc/nginx/snippets/metasfresh-locations.conf;
}
+5
View File
@@ -0,0 +1,5 @@
server {
listen 80;
server_name _;
include /etc/nginx/snippets/metasfresh-locations.conf;
}
+49
View File
@@ -0,0 +1,49 @@
#!/bin/sh
# Patch config.js, set the webapi upstream, and enable SSL if certs are mounted.
set -eu
DIST=/opt/metasfresh-webui-frontend/dist
CONF_D=/etc/nginx/conf.d
CERT_DIR=/etc/nginx/certs
if [ -n "${WEBAPI_URL:-}" ]; then
sed -i "s,http://MYDOCKERHOST:PORT,${WEBAPI_URL},g" "$DIST/config.js"
sed -i "s,http://MYDOCKERHOST:PORT,${WEBAPI_URL},g" "$DIST/mobile/config.js"
fi
# Default plain HTTP; override with WEBAPI_UPSTREAM (e.g. https://webapi:8443).
sed -i "s|__WEBAPI_UPSTREAM__|${WEBAPI_UPSTREAM:-http://webapi:8080}|g" \
/etc/nginx/snippets/metasfresh-locations.conf
CERT="$CERT_DIR/fullchain.pem"
KEY="$CERT_DIR/privkey.pem"
if [ ! -e "$CERT" ] && [ ! -e "$KEY" ]; then
rm -f "$CONF_D/webui-ssl.conf"
echo "[METASFRESH] Running Non-SSL!"
else
[ -e "$CERT" ] || { echo "[METASFRESH] FATAL: privkey.pem present but fullchain.pem missing"; exit 1; }
[ -e "$KEY" ] || { echo "[METASFRESH] FATAL: fullchain.pem present but privkey.pem missing"; exit 1; }
[ -s "$CERT" ] || { echo "[METASFRESH] FATAL: fullchain.pem is empty"; exit 1; }
[ -s "$KEY" ] || { echo "[METASFRESH] FATAL: privkey.pem is empty"; exit 1; }
# Match key and cert by public key (RSA and EC).
cert_pub=$(openssl x509 -in "$CERT" -noout -pubkey 2>/dev/null) \
|| { echo "[METASFRESH] FATAL: fullchain.pem is not a valid certificate"; exit 1; }
key_pub=$(openssl pkey -in "$KEY" -pubout 2>/dev/null) \
|| { echo "[METASFRESH] FATAL: privkey.pem is not a valid private key"; exit 1; }
[ "$cert_pub" = "$key_pub" ] \
|| { echo "[METASFRESH] FATAL: privkey.pem does not match fullchain.pem"; exit 1; }
# Expiry is a warning only; an expired cert still serves.
if ! openssl x509 -in "$CERT" -noout -checkend 0 >/dev/null 2>&1; then
echo "[METASFRESH] WARNING: fullchain.pem is EXPIRED"
elif ! openssl x509 -in "$CERT" -noout -checkend 2592000 >/dev/null 2>&1; then
echo "[METASFRESH] WARNING: fullchain.pem expires within 30 days"
fi
cp "$CONF_D/webui-ssl.conf.disabled" "$CONF_D/webui-ssl.conf"
sed -i 's/\bhttp\b/https/g' "$DIST/config.js" "$DIST/mobile/config.js"
nginx -t || { echo "[METASFRESH] FATAL: nginx config test failed"; exit 1; }
echo "[METASFRESH] Activated SSL!"
fi
+67
View File
@@ -0,0 +1,67 @@
# Shared locations for the HTTP and SSL servers.
# __WEBAPI_UPSTREAM__ is replaced by the entrypoint (default http://webapi:8080).
root /opt/metasfresh-webui-frontend/dist;
index index.html;
proxy_buffering off;
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_set_header X-Forwarded-Proto $forwarded_proto;
proxy_buffers 256 16k;
proxy_buffer_size 16k;
proxy_read_timeout 600s;
client_max_body_size 100M;
# webapi
location /rest { proxy_pass __WEBAPI_UPSTREAM__; }
location /info { proxy_pass __WEBAPI_UPSTREAM__; }
location /configuration { proxy_pass __WEBAPI_UPSTREAM__; }
location /oauth2 { proxy_pass __WEBAPI_UPSTREAM__; }
location /login/oauth2 { proxy_pass __WEBAPI_UPSTREAM__; }
location /swagger-ui.html { proxy_pass __WEBAPI_UPSTREAM__; }
location /swagger-ui/ { proxy_pass __WEBAPI_UPSTREAM__; }
location /swagger-resources { proxy_pass __WEBAPI_UPSTREAM__; }
location /v2/api-docs { proxy_pass __WEBAPI_UPSTREAM__; }
location /v3/api-docs { proxy_pass __WEBAPI_UPSTREAM__; }
location /webjars/springfox-swagger-ui { proxy_pass __WEBAPI_UPSTREAM__; }
location /stomp {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
client_max_body_size 50M;
proxy_pass __WEBAPI_UPSTREAM__;
}
# app
location = /app { return 308 /app/; }
location /app/ {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
client_max_body_size 50M;
proxy_pass http://app:8282/;
}
# static + SPA + mobile
location = /index.html {
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache";
expires -1;
}
location = /service-worker.js {
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache";
expires -1;
}
location /mobile/ {
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache";
expires -1;
try_files $uri /mobile/index.html;
}
location / {
try_files $uri /index.html;
}
-121
View File
@@ -1,121 +0,0 @@
<VirtualHost *:80>
ProxyRequests Off
DocumentRoot /opt/metasfresh-webui-frontend/dist/
# Logging
ErrorLog ${APACHE_LOG_DIR}/webui_error.log
CustomLog ${APACHE_LOG_DIR}/webui_access.log combined
# Debugging
# NOTE: pls comment the ErrorLog and CustomLog entries above
#ErrorLog /dev/stdout
#TransferLog /dev/stdout
#LogLevel alert rewrite:trace8
<Location /rest>
Order allow,deny
Allow from all
ProxyPass http://webapi:8080/rest/ retry=0 acquire=3000 timeout=600 Keepalive=On
ProxyPassReverse http://webapi:8080/rest/
</Location>
<Location /stomp>
Order allow,deny
Allow from all
RewriteEngine on
RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
RewriteCond %{HTTP:CONNECTION} Upgrade$ [NC]
RewriteRule .* ws://webapi:8080%{REQUEST_URI} [P]
ProxyPass ws://webapi:8080/stomp/ retry=0 acquire=3000 timeout=600 Keepalive=On
ProxyPassReverse ws://webapi:8080/stomp/
ProxyPass http://webapi:8080/stomp/ retry=0 acquire=3000 timeout=600 Keepalive=On
ProxyPassReverse http://webapi:8080/stomp/
</Location>
<Location /info>
Order allow,deny
Allow from all
ProxyPass http://webapi:8080/info retry=0 acquire=3000 timeout=600 Keepalive=On
ProxyPassReverse http://webapi:8080/info
</Location>
<Location /swagger-ui.html>
Order allow,deny
Allow from all
ProxyPass http://webapi:8080/swagger-ui.html retry=0 acquire=3000 timeout=600 Keepalive=On
ProxyPassReverse http://webapi:8080/swagger-ui.html
</Location>
<Location /v2/api-docs>
Order allow,deny
Allow from all
ProxyPass http://webapi:8080/v2/api-docs/ retry=0 acquire=3000 timeout=600 Keepalive=On
ProxyPassReverse http://webapi:8080/v2/api-docs/
</Location>
<Location /swagger-resources>
Order allow,deny
Allow from all
ProxyPass http://webapi:8080/swagger-resources/ retry=0 acquire=3000 timeout=600 Keepalive=On
ProxyPassReverse http://webapi:8080/swagger-resources/
</Location>
<Location /webjars/springfox-swagger-ui>
Order allow,deny
Allow from all
ProxyPass http://webapi:8080/webjars/springfox-swagger-ui/ retry=0 acquire=3000 timeout=600 Keepalive=On
ProxyPassReverse http://webapi:8080/webjars/springfox-swagger-ui/
</Location>
<Location /configuration>
Order allow,deny
Allow from all
ProxyPass http://webapi:8080/configuration/ retry=0 acquire=3000 timeout=600 Keepalive=On
ProxyPassReverse http://webapi:8080/configuration/
</Location>
<Location /info>
Order allow,deny
Allow from all
ProxyPass http://webapi:8080/info retry=0 acquire=3000 timeout=600 Keepalive=On
ProxyPassReverse http://webapi:8080/info
</Location>
<Location /mobile>
Order allow,deny
Allow from all
FileETag None
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 21 Oct 2015 07:28:00 GMT"
</Location>
<Directory /opt/metasfresh-webui-frontend/dist/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
RewriteEngine On
# Existing file or directory
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
# mobile UI
RewriteCond %{REQUEST_URI} ^/mobile
RewriteRule ^ /mobile/index.html [L]
# Fallback:
RewriteRule ^ /index.html
</Directory>
<Files index.html>
FileETag None
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 21 Oct 2015 07:28:00 GMT"
</Files>
</VirtualHost>
@@ -1,133 +0,0 @@
<IfModule mod_ssl.c>
<VirtualHost *:443>
ProxyRequests Off
DocumentRoot /opt/metasfresh-webui-frontend/dist/
# Logging
ErrorLog ${APACHE_LOG_DIR}/webui_error.log
CustomLog ${APACHE_LOG_DIR}/webui_access.log combined
# Debugging
# NOTE: pls comment the ErrorLog and CustomLog entries above
#ErrorLog /dev/stdout
#TransferLog /dev/stdout
#LogLevel alert rewrite:trace8
<Location /rest>
Order allow,deny
Allow from all
ProxyPass http://webapi:8080/rest/ retry=0 acquire=3000 timeout=600 Keepalive=On
ProxyPassReverse http://webapi:8080/rest/
</Location>
<Location /stomp>
Order allow,deny
Allow from all
RewriteEngine on
RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
RewriteCond %{HTTP:CONNECTION} Upgrade$ [NC]
RewriteRule .* ws://webapi:8080%{REQUEST_URI} [P]
ProxyPass wss://webapi:8080/stomp/ retry=0 acquire=3000 timeout=600 Keepalive=On
ProxyPassReverse wss://webapi:8080/stomp/
ProxyPass http://webapi:8080/stomp/ retry=0 acquire=3000 timeout=600 Keepalive=On
ProxyPassReverse http://webapi:8080/stomp/
</Location>
<Location /info>
Order allow,deny
Allow from all
ProxyPass http://webapi:8080/info retry=0 acquire=3000 timeout=600 Keepalive=On
ProxyPassReverse http://webapi:8080/info
</Location>
<Location /swagger-ui.html>
Order allow,deny
Allow from all
ProxyPass http://webapi:8080/swagger-ui.html retry=0 acquire=3000 timeout=600 Keepalive=On
ProxyPassReverse http://webapi:8080/swagger-ui.html
</Location>
<Location /v2/api-docs>
Order allow,deny
Allow from all
ProxyPass http://webapi:8080/v2/api-docs/ retry=0 acquire=3000 timeout=600 Keepalive=On
ProxyPassReverse http://webapi:8080/v2/api-docs/
</Location>
<Location /swagger-resources>
Order allow,deny
Allow from all
ProxyPass http://webapi:8080/swagger-resources/ retry=0 acquire=3000 timeout=600 Keepalive=On
ProxyPassReverse http://webapi:8080/swagger-resources/
</Location>
<Location /webjars/springfox-swagger-ui>
Order allow,deny
Allow from all
ProxyPass http://webapi:8080/webjars/springfox-swagger-ui/ retry=0 acquire=3000 timeout=600 Keepalive=On
ProxyPassReverse http://webapi:8080/webjars/springfox-swagger-ui/
</Location>
<Location /configuration>
Order allow,deny
Allow from all
ProxyPass http://webapi:8080/configuration/ retry=0 acquire=3000 timeout=600 Keepalive=On
ProxyPassReverse http://webapi:8080/configuration/
</Location>
<Location /info>
Order allow,deny
Allow from all
ProxyPass http://webapi:8080/info retry=0 acquire=3000 timeout=600 Keepalive=On
ProxyPassReverse http://webapi:8080/info
</Location>
<Location /mobile>
Order allow,deny
Allow from all
FileETag None
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 21 Oct 2015 07:28:00 GMT"
</Location>
<Directory /opt/metasfresh-webui-frontend/dist/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
RewriteEngine On
# Existing file or directory
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
# mobile UI
RewriteCond %{REQUEST_URI} ^/mobile
RewriteRule ^ /mobile/index.html [L]
# Fallback:
RewriteRule ^ /index.html
</Directory>
<Files index.html>
FileETag None
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 21 Oct 2015 07:28:00 GMT"
</Files>
<Files service-worker.js>
FileETag None
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 21 Oct 2015 07:28:00 GMT"
</Files>
SSLCertificateFile /etc/apache2/certs/fullchain.pem
SSLCertificateKeyFile /etc/apache2/certs/privkey.pem
</VirtualHost>
</IfModule>
+4 -1
View File
@@ -1,3 +1,6 @@
const config = {
SERVER_URL: 'http://MYDOCKERHOST:PORT/app',
SERVER_URL: 'http://MYDOCKERHOST:PORT/app'
};
window.config = {
SERVER_URL: 'http://MYDOCKERHOST:PORT/app'
};