Skip to content

Commit cc87760

Browse files
committed
fix: nginx template variable escaping and add documentation
- Add comprehensive comments explaining envsubst variable escaping - Fix proxy_set_header directives using for nginx variables - Add DOLLAR=$ environment variable for template processing - Add TODO comments for HTTPS configuration section fixes - Resolves nginx proxy configuration errors during service startup
1 parent f09efaf commit cc87760

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

infrastructure/config/environments/local.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
ENVIRONMENT=local
33
GENERATION_DATE=$(date '+%Y-%m-%d %H:%M:%S')
44

5+
# Template processing variables
6+
DOLLAR=$
7+
58
# === SECRETS (Only these variables will be in Docker environment) ===
69

710
# Database Secrets

infrastructure/config/templates/nginx.conf.tpl

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
# Nginx Configuration Template for Torrust Tracker Demo
2+
#
3+
# Variable Escaping Notes:
4+
# - This template is processed by envsubst which substitutes all $VARIABLE patterns
5+
# - Nginx variables (like $proxy_add_x_forwarded_for, $host, $http_upgrade) must be escaped
6+
# - Use ${DOLLAR} environment variable to represent literal $ in nginx config
7+
# - Example: ${DOLLAR}proxy_add_x_forwarded_for becomes $proxy_add_x_forwarded_for
8+
#
9+
# TODO: Fix the commented HTTPS configuration section below
10+
# - The HTTPS configuration has inconsistent variable escaping
11+
# - Some nginx variables use literal $ (incorrect) while others should use ${DOLLAR}
12+
# - Line 117: proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; (needs ${DOLLAR})
13+
# - Lines with $host, $http_upgrade, $connection_upgrade also need escaping
14+
# - SSL certificate paths and other static values are correct as-is
15+
116
server
217
{
318
listen 80;
@@ -11,13 +26,13 @@ server
1126
location /api/
1227
{
1328
proxy_pass http://tracker:1212/api/;
14-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
29+
proxy_set_header X-Forwarded-For ${DOLLAR}proxy_add_x_forwarded_for;
1530
}
1631

1732
location /
1833
{
1934
proxy_pass http://tracker:7070;
20-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
35+
proxy_set_header X-Forwarded-For ${DOLLAR}proxy_add_x_forwarded_for;
2136
}
2237

2338
location ~ /.well-known/acme-challenge
@@ -109,7 +124,7 @@ server
109124
# #add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
110125
# # enable strict transport security only if you understand the implications
111126
#
112-
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
127+
# proxy_set_header X-Forwarded-For ${DOLLAR}proxy_add_x_forwarded_for;
113128
# }
114129
#
115130
# root /var/www/html;

0 commit comments

Comments
 (0)