Initial push of Plunk Next
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
services:
|
||||
db:
|
||||
image: postgres
|
||||
ports:
|
||||
- 55432:5432
|
||||
environment:
|
||||
POSTGRES_PASSWORD: postgres
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_DB: postgres
|
||||
|
||||
redis:
|
||||
image: redis
|
||||
command: redis-server --appendonly yes
|
||||
ports:
|
||||
- 56379:6379
|
||||
volumes:
|
||||
- redis_data:/data
|
||||
|
||||
minio:
|
||||
image: minio/minio:latest
|
||||
command: server /data --console-address ":9001"
|
||||
ports:
|
||||
- 9000:9000
|
||||
- 9001:9001
|
||||
environment:
|
||||
MINIO_ROOT_USER: plunk
|
||||
MINIO_ROOT_PASSWORD: plunkminiopass
|
||||
volumes:
|
||||
- minio_data:/data
|
||||
|
||||
volumes:
|
||||
redis_data:
|
||||
minio_data:
|
||||
@@ -0,0 +1,165 @@
|
||||
# Nginx Configuration for Plunk - Subdomain-based Routing
|
||||
# This configuration routes traffic based on subdomains:
|
||||
# - api.example.com -> API server (port 8080)
|
||||
# - app.example.com -> Web dashboard (port 3000)
|
||||
# - www.example.com -> Landing page (port 4000)
|
||||
# - docs.example.com -> Documentation (port 1000)
|
||||
|
||||
# Upstream definitions
|
||||
upstream plunk_api {
|
||||
server 127.0.0.1:8080;
|
||||
}
|
||||
|
||||
upstream plunk_web {
|
||||
server 127.0.0.1:3000;
|
||||
}
|
||||
|
||||
upstream plunk_landing {
|
||||
server 127.0.0.1:4000;
|
||||
}
|
||||
|
||||
upstream plunk_wiki {
|
||||
server 127.0.0.1:1000;
|
||||
}
|
||||
|
||||
upstream plunk_acme_challenge {
|
||||
server 127.0.0.1:8888;
|
||||
}
|
||||
|
||||
# API Server (also serves as default_server for unmatched domains)
|
||||
server {
|
||||
listen ${NGINX_PORT} default_server;
|
||||
server_name ${API_DOMAIN};
|
||||
|
||||
client_max_body_size 10M;
|
||||
|
||||
# ACME challenges should be handled by SMTP server, not API
|
||||
# This catches ALL ACME challenges, including for SMTP_DOMAIN
|
||||
location /.well-known/acme-challenge/ {
|
||||
proxy_pass http://plunk_acme_challenge;
|
||||
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 $scheme;
|
||||
}
|
||||
|
||||
location / {
|
||||
proxy_pass http://plunk_api;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection 'upgrade';
|
||||
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 $scheme;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
}
|
||||
}
|
||||
|
||||
# Web Dashboard
|
||||
server {
|
||||
listen ${NGINX_PORT};
|
||||
server_name ${DASHBOARD_DOMAIN};
|
||||
|
||||
client_max_body_size 10M;
|
||||
|
||||
# ACME challenges fallback
|
||||
location /.well-known/acme-challenge/ {
|
||||
proxy_pass http://plunk_acme_challenge;
|
||||
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 $scheme;
|
||||
}
|
||||
|
||||
location / {
|
||||
proxy_pass http://plunk_web;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection 'upgrade';
|
||||
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 $scheme;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
}
|
||||
}
|
||||
|
||||
# Landing Page
|
||||
server {
|
||||
listen ${NGINX_PORT};
|
||||
server_name ${LANDING_DOMAIN};
|
||||
|
||||
client_max_body_size 10M;
|
||||
|
||||
# ACME challenges fallback
|
||||
location /.well-known/acme-challenge/ {
|
||||
proxy_pass http://plunk_acme_challenge;
|
||||
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 $scheme;
|
||||
}
|
||||
|
||||
location / {
|
||||
proxy_pass http://plunk_landing;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection 'upgrade';
|
||||
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 $scheme;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
}
|
||||
}
|
||||
|
||||
# Documentation (optional)
|
||||
server {
|
||||
listen ${NGINX_PORT};
|
||||
server_name ${WIKI_DOMAIN};
|
||||
|
||||
client_max_body_size 10M;
|
||||
|
||||
# ACME challenges fallback
|
||||
location /.well-known/acme-challenge/ {
|
||||
proxy_pass http://plunk_acme_challenge;
|
||||
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 $scheme;
|
||||
}
|
||||
|
||||
location / {
|
||||
proxy_pass http://plunk_wiki;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection 'upgrade';
|
||||
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 $scheme;
|
||||
proxy_cache_bypass $http_upgrade;
|
||||
}
|
||||
}
|
||||
|
||||
# ACME Challenge Proxy (for SMTP domain certificate generation)
|
||||
# This proxies Let's Encrypt ACME HTTP-01 challenges to the SMTP server's challenge handler
|
||||
server {
|
||||
listen ${NGINX_PORT};
|
||||
server_name ${SMTP_DOMAIN};
|
||||
|
||||
# Proxy ACME challenges to SMTP server's internal challenge server
|
||||
location /.well-known/acme-challenge/ {
|
||||
proxy_pass http://plunk_acme_challenge;
|
||||
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 $scheme;
|
||||
}
|
||||
|
||||
# Deny all other requests to SMTP domain
|
||||
location / {
|
||||
return 404;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
# Nginx Setup Script for Plunk
|
||||
# Configures nginx reverse proxy with subdomain-based routing
|
||||
|
||||
echo "🔧 Configuring nginx reverse proxy..."
|
||||
|
||||
NGINX_CONFIG_DIR="/etc/nginx"
|
||||
NGINX_CONF_D="${NGINX_CONFIG_DIR}/conf.d"
|
||||
|
||||
# Create nginx directories if they don't exist
|
||||
mkdir -p "${NGINX_CONF_D}"
|
||||
|
||||
echo "🌐 Using subdomain-based routing"
|
||||
|
||||
# Set defaults if not provided
|
||||
export API_DOMAIN="${API_DOMAIN:-api.localhost}"
|
||||
export DASHBOARD_DOMAIN="${DASHBOARD_DOMAIN:-app.localhost}"
|
||||
export LANDING_DOMAIN="${LANDING_DOMAIN:-www.localhost}"
|
||||
export WIKI_DOMAIN="${WIKI_DOMAIN:-docs.localhost}"
|
||||
export SMTP_DOMAIN="${SMTP_DOMAIN:-smtp.localhost}"
|
||||
export NGINX_PORT="${NGINX_PORT:-80}"
|
||||
export USE_HTTPS="${USE_HTTPS:-false}"
|
||||
|
||||
# Determine protocol based on USE_HTTPS
|
||||
if [ "$USE_HTTPS" = "true" ]; then
|
||||
PROTOCOL="https"
|
||||
else
|
||||
PROTOCOL="http"
|
||||
fi
|
||||
|
||||
# Validate required environment variables
|
||||
if [ -z "$API_DOMAIN" ] || [ -z "$DASHBOARD_DOMAIN" ] || [ -z "$LANDING_DOMAIN" ]; then
|
||||
echo "⚠️ Warning: Some domain variables are not set. Using defaults."
|
||||
echo " API_DOMAIN=${API_DOMAIN}"
|
||||
echo " DASHBOARD_DOMAIN=${DASHBOARD_DOMAIN}"
|
||||
echo " LANDING_DOMAIN=${LANDING_DOMAIN}"
|
||||
echo " WIKI_DOMAIN=${WIKI_DOMAIN}"
|
||||
fi
|
||||
|
||||
# Auto-configure API URIs based on domains and protocol
|
||||
export API_URI="${API_URI:-${PROTOCOL}://${API_DOMAIN}}"
|
||||
export DASHBOARD_URI="${DASHBOARD_URI:-${PROTOCOL}://${DASHBOARD_DOMAIN}}"
|
||||
export LANDING_URI="${LANDING_URI:-${PROTOCOL}://${LANDING_DOMAIN}}"
|
||||
export WIKI_URI="${WIKI_URI:-${PROTOCOL}://${WIKI_DOMAIN}}"
|
||||
|
||||
# Generate nginx configuration from template
|
||||
echo "📝 Generating nginx configuration..."
|
||||
|
||||
# If SMTP_DOMAIN is not set or empty, use a placeholder to prevent nginx config errors
|
||||
if [ -z "$SMTP_DOMAIN" ]; then
|
||||
echo "⚠️ SMTP_DOMAIN not set - ACME challenge proxy will not be configured"
|
||||
export SMTP_DOMAIN="_" # nginx wildcard that won't match any real domain
|
||||
fi
|
||||
|
||||
envsubst '${NGINX_PORT} ${API_DOMAIN} ${DASHBOARD_DOMAIN} ${LANDING_DOMAIN} ${WIKI_DOMAIN} ${SMTP_DOMAIN}' \
|
||||
< /app/docker/nginx/nginx.conf.template \
|
||||
> "${NGINX_CONF_D}/plunk.conf"
|
||||
|
||||
# Always create nginx.conf (overwrite default from package)
|
||||
cat > "${NGINX_CONFIG_DIR}/nginx.conf" << 'EOF'
|
||||
worker_processes auto;
|
||||
error_log /var/log/nginx/error.log warn;
|
||||
pid /run/nginx/nginx.pid;
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
http {
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||
'$status $body_bytes_sent "$http_referer" '
|
||||
'"$http_user_agent" "$http_x_forwarded_for"';
|
||||
|
||||
access_log /var/log/nginx/access.log main;
|
||||
|
||||
sendfile on;
|
||||
tcp_nopush on;
|
||||
tcp_nodelay on;
|
||||
keepalive_timeout 65;
|
||||
types_hash_max_size 2048;
|
||||
server_names_hash_bucket_size 128;
|
||||
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
gzip_proxied any;
|
||||
gzip_comp_level 6;
|
||||
gzip_types text/plain text/css text/xml text/javascript application/json application/javascript application/xml+rss application/rss+xml font/truetype font/opentype application/vnd.ms-fontobject image/svg+xml;
|
||||
|
||||
# Include server configurations
|
||||
include /etc/nginx/conf.d/*.conf;
|
||||
}
|
||||
EOF
|
||||
|
||||
echo "✅ Nginx configuration complete!"
|
||||
echo " Config file: ${NGINX_CONF_D}/plunk.conf"
|
||||
echo " API Domain: ${API_DOMAIN}"
|
||||
echo " Dashboard Domain: ${DASHBOARD_DOMAIN}"
|
||||
echo " Landing Domain: ${LANDING_DOMAIN}"
|
||||
echo " Wiki Domain: ${WIKI_DOMAIN}"
|
||||
echo " SMTP Domain: ${SMTP_DOMAIN}"
|
||||
Reference in New Issue
Block a user