Skip to content

Commit 10c2ce3

Browse files
committed
Add a very simple nginx config validation script
1 parent eb3091b commit 10c2ce3

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

test-nginx-config.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
3+
# Script to test nginx.conf.sigil configuration locally using Docker
4+
# This reads the actual nginx.conf.sigil file, strips Dokku template variables, and validates it
5+
6+
set -e
7+
8+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9+
NGINX_SIGIL="$SCRIPT_DIR/nginx.conf.sigil"
10+
TEST_CONFIG="/tmp/test-nginx.conf"
11+
12+
if [ ! -f "$NGINX_SIGIL" ]; then
13+
echo "❌ Error: nginx.conf.sigil not found at $NGINX_SIGIL"
14+
exit 1
15+
fi
16+
17+
echo "🔧 Reading nginx.conf.sigil and creating test config..."
18+
echo ""
19+
20+
# Read nginx.conf.sigil and strip out Dokku template variables
21+
# Comment out include directives
22+
# Remove SSL from listen directives for testing (nginx requires certs to be present)
23+
# Replace SSL cert paths with dummy values
24+
sed -e 's|^.*include {{ \$.DOKKU_ROOT }}/{{ \$.APP }}/nginx.conf.d/\*\.conf;| # include dummy;|g' \
25+
-e 's| ssl http2;| http2;|g' \
26+
-e 's|ssl_certificate.*{{ \$.APP_SSL_PATH }}/server.crt;| # ssl_certificate /dummy/path.crt;|g' \
27+
-e 's|ssl_certificate_key.*{{ \$.APP_SSL_PATH }}/server.key;| # ssl_certificate_key /dummy/path.key;|g' \
28+
"$NGINX_SIGIL" > "$TEST_CONFIG"
29+
30+
echo "✅ Test config created at $TEST_CONFIG"
31+
echo ""
32+
echo "🐳 Testing nginx config with Docker..."
33+
echo ""
34+
35+
# Test the config using nginx in Docker
36+
if docker run --rm -v "$TEST_CONFIG:/etc/nginx/conf.d/default.conf" nginx:alpine nginx -t 2>&1 | grep -q "syntax is ok"; then
37+
echo ""
38+
echo "✅ Nginx configuration is valid!"
39+
echo ""
40+
echo "📝 To manually inspect the test config: cat $TEST_CONFIG"
41+
echo "🗑️ To remove the test config: rm $TEST_CONFIG"
42+
exit 0
43+
else
44+
echo ""
45+
echo "❌ Nginx configuration has errors!"
46+
echo ""
47+
echo "📝 Check the test config: cat $TEST_CONFIG"
48+
exit 1
49+
fi

0 commit comments

Comments
 (0)