Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add optional FORCE_HTTPS_REDIRECT flag to install.sh method (#1181)
Leendert de Borst56e82cd046e8
diff --git a/.env.example b/.env.exampleindex 20533aca8..1f475fa73 100644--- a/.env.example+++ b/.env.example@@ -26,6 +26,9 @@ HTTPS_PORT=443SMTP_PORT=25SMTP_TLS_PORT=587+# Whether to force redirect all HTTP traffic (80) to HTTPS (443). Defaults to true.+FORCE_HTTPS_REDIRECT=true+# ===========================================# EMAIL SERVER CONFIGURATION# ===========================================diff --git a/apps/server/Dockerfile b/apps/server/Dockerfileindex e8e8b0364..5fd29f990 100644--- a/apps/server/Dockerfile+++ b/apps/server/Dockerfile@@ -10,8 +10,8 @@ LABEL org.opencontainers.image.description="Nginx reverse proxy for AliasVault.# Install OpenSSLRUN apk add --no-cache openssl-# Copy configuration and entrypoint script-COPY apps/server/nginx.conf /etc/nginx/nginx.conf+# Copy all nginx configurations and entrypoint script+COPY apps/server/nginx*.conf /etc/nginx/COPY apps/server/status.html /usr/share/nginx/html/status.htmlCOPY apps/server/entrypoint.sh /docker-entrypoint.shdiff --git a/apps/server/entrypoint.sh b/apps/server/entrypoint.shindex 41ad6cd17..eb2a53f6b 100644--- a/apps/server/entrypoint.sh+++ b/apps/server/entrypoint.sh@@ -3,6 +3,17 @@# Create SSL directory if it doesn't existmkdir -p /etc/nginx/ssl+# Select the appropriate nginx configuration based on FORCE_HTTPS_REDIRECT+# Default to true (nginx-443.conf) for backward compatibility+# Only disable redirect if explicitly set to "false"+if [ "${FORCE_HTTPS_REDIRECT:-true}" = "false" ]; then+ echo "Using nginx-80-443.conf (HTTP and HTTPS without redirect)"+ cp /etc/nginx/nginx-80-443.conf /etc/nginx/nginx.conf+else+ echo "Using nginx-443.conf (HTTP to HTTPS redirect enabled - default)"+ cp /etc/nginx/nginx-443.conf /etc/nginx/nginx.conf+fi+# Generate self-signed SSL certificate if not existsif [ ! -f /etc/nginx/ssl/cert.pem ] || [ ! -f /etc/nginx/ssl/key.pem ]; thenecho "Generating new SSL certificate (10 years validity)..."diff --git a/apps/server/nginx-443.conf b/apps/server/nginx-443.confnew file mode 100644index 000000000..69af1f4aa--- /dev/null+++ b/apps/server/nginx-443.conf@@ -0,0 +1,143 @@+# This is the Nginx configuration file for the AliasVault reverse-proxy container.+# which exposes all AliasVault services via 443 (HTTPS) with a self-signed or Let's Encrypt certificate.+# It also redirects all non-ACME challenge requests from HTTP to HTTPS.+events {+ worker_connections 1024;+}++http {+ client_max_body_size 25M;++ upstream client {+ server client:3000 max_fails=1 fail_timeout=5s;+ }++ upstream api {+ server api:3001 max_fails=1 fail_timeout=5s;+ }++ upstream admin {+ server admin:3002 max_fails=1 fail_timeout=5s;+ }++ # Preserve any existing X-Forwarded-* headers, this is relevant if AliasVault+ # is running behind another reverse proxy.+ set_real_ip_from 10.0.0.0/8;+ set_real_ip_from 172.16.0.0/12;+ set_real_ip_from 192.168.0.0/16;+ real_ip_header X-Forwarded-For;+ real_ip_recursive on;++ include /etc/nginx/mime.types;+ default_type application/octet-stream;++ # Enable gzip compression, which reduces the amount of data that needs to be transferred+ # to speed up WASM load times.+ gzip on;+ gzip_vary on;+ gzip_proxied any;+ gzip_comp_level 6;+ gzip_buffers 16 8k;+ gzip_http_version 1.1;+ gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;++ server {+ listen 80;+ server_name _;++ # Handle ACME challenge for Let's Encrypt certificate validation+ location /.well-known/acme-challenge/ {+ allow all;+ root /var/www/certbot;+ try_files $uri =404;+ default_type "text/plain";+ add_header Cache-Control "no-cache";+ break;+ }++ # Redirect all other HTTP traffic to HTTPS+ location / {+ return 301 https://$host$request_uri;+ }+ }++ server {+ listen 443 ssl;+ server_name _;++ # Include the appropriate SSL certificate configuration generated+ # by the entrypoint script.+ include /etc/nginx/ssl.conf;++ # Security headers+ add_header Referrer-Policy "strict-origin-when-cross-origin" always;+ add_header X-Content-Type-Options "nosniff" always;+ add_header X-Frame-Options "SAMEORIGIN" always;+ add_header Cross-Origin-Resource-Policy "same-origin" always;+ add_header Content-Security-Policy "frame-ancestors 'self'" always;++ # Root for static files+ root /usr/share/nginx/html;++ # Error page handler location (internal use only)+ location = /status.html {+ internal;+ try_files /status.html =404;+ add_header Cache-Control "no-cache, no-store, must-revalidate";+ add_header Pragma "no-cache";+ add_header Expires "0";+ }++ # Admin interface+ location /admin {+ proxy_pass http://admin;+ proxy_set_header Host $http_host;+ proxy_set_header X-Real-IP $remote_addr;+ proxy_set_header X-Forwarded-Proto https;+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;+ proxy_set_header X-Forwarded-Prefix /admin/;++ # Rewrite HTTP redirects to HTTPS+ proxy_redirect http:// https://;++ # Add WebSocket support for Blazor server+ proxy_http_version 1.1;+ proxy_set_header Upgrade $http_upgrade;+ proxy_set_header Connection "upgrade";+ proxy_read_timeout 86400;++ # Show status page if admin is down+ proxy_intercept_errors on;+ error_page 502 503 504 =503 /status.html;+ }++ # API endpoints+ location /api {+ proxy_pass http://api;+ proxy_set_header Host $http_host;+ proxy_set_header X-Real-IP $remote_addr;+ proxy_set_header X-Forwarded-Proto $scheme;+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;++ # Show status page if api is down+ proxy_intercept_errors on;+ error_page 502 503 504 =503 /status.html;+ }++ # Client app (root path)+ location / {+ proxy_pass http://client;+ proxy_set_header Host $http_host;+ proxy_set_header X-Real-IP $remote_addr;+ proxy_set_header X-Forwarded-Proto $scheme;+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;++ # Rewrite HTTP redirects to HTTPS+ proxy_redirect http:// https://;++ # Show status page if client is down+ proxy_intercept_errors on;+ error_page 502 503 504 =503 /status.html;+ }+ }+}diff --git a/apps/server/nginx-80-443.conf b/apps/server/nginx-80-443.confnew file mode 100644index 000000000..23dad877d--- /dev/null+++ b/apps/server/nginx-80-443.conf@@ -0,0 +1,128 @@+# This is the main Nginx configuration file for the AliasVault reverse-proxy container.+# which exposes all AliasVault services via both 80 (HTTP)+# and 443 (HTTPS) with either a self-signed or Let's Encrypt certificate.+events {+ worker_connections 1024;+}++http {+ client_max_body_size 25M;++ upstream client {+ server client:3000 max_fails=1 fail_timeout=5s;+ }++ upstream api {+ server api:3001 max_fails=1 fail_timeout=5s;+ }++ upstream admin {+ server admin:3002 max_fails=1 fail_timeout=5s;+ }++ # Preserve any existing X-Forwarded-* headers, this is relevant if AliasVault+ # is running behind another reverse proxy.+ set_real_ip_from 10.0.0.0/8;+ set_real_ip_from 172.16.0.0/12;+ set_real_ip_from 192.168.0.0/16;+ real_ip_header X-Forwarded-For;+ real_ip_recursive on;++ include /etc/nginx/mime.types;+ default_type application/octet-stream;++ # Enable gzip compression, which reduces the amount of data that needs to be transferred+ # to speed up WASM load times.+ gzip on;+ gzip_vary on;+ gzip_proxied any;+ gzip_comp_level 6;+ gzip_buffers 16 8k;+ gzip_http_version 1.1;+ gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;++ server {+ listen 80;+ listen 443 ssl;+ server_name _;++ # Include the appropriate SSL certificate configuration generated+ # by the entrypoint script (only applies to 443).+ include /etc/nginx/ssl.conf;++ # Security headers+ add_header Referrer-Policy "strict-origin-when-cross-origin" always;+ add_header X-Content-Type-Options "nosniff" always;+ add_header X-Frame-Options "SAMEORIGIN" always;+ add_header Cross-Origin-Resource-Policy "same-origin" always;+ add_header Content-Security-Policy "frame-ancestors 'self'" always;++ # Root for static files+ root /usr/share/nginx/html;++ # Handle ACME challenge for Let's Encrypt certificate validation+ location /.well-known/acme-challenge/ {+ allow all;+ root /var/www/certbot;+ try_files $uri =404;+ default_type "text/plain";+ add_header Cache-Control "no-cache";+ break;+ }++ # Error page handler location (internal use only)+ location = /status.html {+ internal;+ try_files /status.html =404;+ add_header Cache-Control "no-cache, no-store, must-revalidate";+ add_header Pragma "no-cache";+ add_header Expires "0";+ }++ # Admin interface+ location /admin {+ proxy_pass http://admin;+ proxy_set_header Host $http_host;+ proxy_set_header X-Real-IP $remote_addr;+ proxy_set_header X-Forwarded-Proto $scheme;+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;+ proxy_set_header X-Forwarded-Prefix /admin/;++ # Add WebSocket support for Blazor server+ proxy_http_version 1.1;+ proxy_set_header Upgrade $http_upgrade;+ proxy_set_header Connection "upgrade";+ proxy_read_timeout 86400;++ # Show status page if admin is down+ proxy_intercept_errors on;+ error_page 502 503 504 =503 /status.html;+ }++ # API endpoints+ location /api {+ proxy_pass http://api;+ proxy_set_header Host $http_host;+ proxy_set_header X-Real-IP $remote_addr;+ proxy_set_header X-Forwarded-Proto $scheme;+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;++ # Show status page if api is down+ proxy_intercept_errors on;+ error_page 502 503 504 =503 /status.html;+ }++ # Client app (root path)+ location / {+ proxy_pass http://client;+ proxy_set_header Host $http_host;+ proxy_set_header X-Real-IP $remote_addr;+ proxy_set_header X-Forwarded-Proto $scheme;+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;++ # Show status page if client is down+ proxy_intercept_errors on;+ error_page 502 503 504 =503 /status.html;+ }+ }+}