Skip to content

Commit b6df4d9

Browse files
Rene-Roscherclaude
andcommitted
feat: Auto-derive Nginx server_name & Certbot domains from APP_URL
- Nginx server_name now automatically derived from APP_URL - CERTBOT_DOMAINS automatically derived from APP_URL if not set - Extracts domain by removing protocol (https://) and trailing slash - Fallback to _ (catch-all) if APP_URL not set Benefits: - Single source of truth (APP_URL) for domain configuration - No need to set NGINX_SERVER_NAME or CERTBOT_DOMAINS separately - Cleaner configuration for Laravel applications 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent b75b4b2 commit b6df4d9

File tree

5 files changed

+37
-7
lines changed

5 files changed

+37
-7
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,8 @@ Thumbs.db
1616
# Temporary
1717
*.tmp
1818
*.temp
19+
20+
# Project-specific configs (not part of universal image)
21+
docker-compose.livck*.yml
22+
.env.livck*
23+
LIVCK-*.md

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,11 @@ services:
9494
OPCACHE_JIT: tracing
9595
OPCACHE_JIT_BUFFER_SIZE: 200M
9696

97-
# SSL
97+
# SSL (CERTBOT_DOMAINS auto-derived from APP_URL if not set)
98+
APP_URL: https://example.com/
9899
CERTBOT_ENABLED: "true"
99-
CERTBOT_DOMAINS: example.com
100100
CERTBOT_EMAIL: admin@example.com
101+
# CERTBOT_DOMAINS: example.com # Optional - auto-derived from APP_URL
101102

102103
# Laravel
103104
LARAVEL_OPTIMIZE_ON_BOOT: "true"
@@ -202,12 +203,15 @@ NGINX_CLIENT_MAX_BODY_SIZE=200M
202203

203204
### SSL/Certbot
204205
```bash
206+
APP_URL=https://example.com/ # Auto-derived for CERTBOT_DOMAINS (strips protocol)
205207
CERTBOT_ENABLED=true
206208
CERTBOT_EMAIL=admin@example.com
207-
CERTBOT_DOMAINS=example.com,www.example.com
209+
CERTBOT_DOMAINS=example.com # Optional - auto-derived from APP_URL if not set
208210
CERTBOT_AUTO_RENEW=true
209211
```
210212

213+
**Auto-Detection:** If `CERTBOT_DOMAINS` is empty, it's automatically derived from `APP_URL` by removing protocol (`https://`) and trailing slash.
214+
211215
### Laravel
212216
```bash
213217
LARAVEL_OPTIMIZE_ON_BOOT=true

rootfs/etc/cont-init.d/01-setup-configs.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@ set -e
33

44
echo "[Init] Generating runtime configurations from ENV variables..."
55

6+
########################################
7+
# Auto-derive Nginx server_name from APP_URL
8+
########################################
9+
if [ -n "${APP_URL}" ]; then
10+
# Extract domain from APP_URL (remove protocol and trailing slash)
11+
export NGINX_SERVER_NAME=$(echo "${APP_URL}" | sed -E 's~^https?://~~' | sed 's~/$~~')
12+
echo "[Init] Auto-derived server_name from APP_URL: ${NGINX_SERVER_NAME}"
13+
else
14+
# Fallback to catch-all
15+
export NGINX_SERVER_NAME="${NGINX_SERVER_NAME:-_}"
16+
echo "[Init] Using server_name: ${NGINX_SERVER_NAME}"
17+
fi
18+
619
########################################
720
# Socket Type Detection (используется für PHP-FPM UND Nginx)
821
########################################
@@ -245,7 +258,7 @@ export APP_ENV=${APP_ENV:-production}
245258
# FPM_PASS is already set at the top of the script
246259

247260
# Substitute ENV variables in Laravel-optimized nginx config
248-
envsubst '${NGINX_WEBROOT} ${FPM_PASS} ${APP_ENV} ${NGINX_GZIP} ${NGINX_GZIP_COMP_LEVEL} ${NGINX_GZIP_MIN_LENGTH} ${NGINX_FASTCGI_BUFFER_SIZE} ${NGINX_FASTCGI_BUFFERS} ${NGINX_FASTCGI_BUSY_BUFFERS_SIZE} ${NGINX_FASTCGI_CONNECT_TIMEOUT} ${NGINX_FASTCGI_SEND_TIMEOUT} ${NGINX_FASTCGI_READ_TIMEOUT}' \
261+
envsubst '${NGINX_SERVER_NAME} ${NGINX_WEBROOT} ${FPM_PASS} ${APP_ENV} ${NGINX_GZIP} ${NGINX_GZIP_COMP_LEVEL} ${NGINX_GZIP_MIN_LENGTH} ${NGINX_FASTCGI_BUFFER_SIZE} ${NGINX_FASTCGI_BUFFERS} ${NGINX_FASTCGI_BUSY_BUFFERS_SIZE} ${NGINX_FASTCGI_CONNECT_TIMEOUT} ${NGINX_FASTCGI_SEND_TIMEOUT} ${NGINX_FASTCGI_READ_TIMEOUT}' \
249262
< /etc/templates/nginx-laravel.conf > /etc/nginx/http.d/default.conf
250263

251264
echo "[Init] Configurations generated successfully!"

rootfs/etc/cont-init.d/03-certbot-setup.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,17 @@ if [ -z "${CERTBOT_EMAIL}" ] || [ "${CERTBOT_EMAIL}" = "admin@example.com" ]; th
1515
CERTBOT_EMAIL=""
1616
fi
1717

18+
# Auto-derive CERTBOT_DOMAINS from APP_URL if not set
1819
if [ -z "${CERTBOT_DOMAINS}" ] || [ "${CERTBOT_DOMAINS}" = "example.com,www.example.com" ]; then
19-
echo "[Certbot] WARNING: CERTBOT_DOMAINS not set or using default. SSL certificates will not be obtained."
20-
exit 0
20+
if [ -n "${APP_URL}" ]; then
21+
# Extract domain from APP_URL (remove protocol and trailing slash)
22+
CERTBOT_DOMAINS=$(echo "${APP_URL}" | sed -E 's~^https?://~~' | sed 's~/$~~')
23+
export CERTBOT_DOMAINS
24+
echo "[Certbot] Auto-derived domain from APP_URL: ${CERTBOT_DOMAINS}"
25+
else
26+
echo "[Certbot] WARNING: CERTBOT_DOMAINS not set or using default. SSL certificates will not be obtained."
27+
exit 0
28+
fi
2129
fi
2230

2331
# Setup Certbot cron for auto-renewal

rootfs/etc/templates/nginx-laravel.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ server {
55
listen 80 default_server;
66
listen [::]:80 default_server;
77

8-
server_name _;
8+
server_name ${NGINX_SERVER_NAME};
99
root ${NGINX_WEBROOT};
1010
index index.php index.html;
1111

0 commit comments

Comments
 (0)