Skip to content

Commit bbe29e9

Browse files
authored
Merge pull request #93 from IABTechLab/sas-UID2-6064-reverse-proxy
Sas UI d2 6064 reverse proxy
2 parents d0a905c + 7749fdb commit bbe29e9

File tree

6 files changed

+438
-48
lines changed

6 files changed

+438
-48
lines changed

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ services:
77
ports:
88
- "80:80"
99
container_name: reverse-proxy
10+
environment:
11+
- DOMAIN=${DOMAIN:-sample-dev.com}
1012

1113
# javascript sdk integrations
1214
javascript-sdk-client-side:

tools/reverse-proxy/Dockerfile

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
FROM nginx:alpine
22

3-
# Install wget for healthcheck
4-
RUN apk add --no-cache wget
3+
# Install wget for healthcheck and gettext for envsubst
4+
RUN apk add --no-cache wget gettext
55

6-
# Copy nginx configuration
7-
COPY default.conf /etc/nginx/conf.d/default.conf
6+
# Create templates directory
7+
RUN mkdir -p /etc/nginx/templates
8+
9+
# Copy nginx configuration template
10+
COPY default.conf.template /etc/nginx/templates/default.conf.template
11+
12+
# Copy entrypoint script
13+
COPY docker-entrypoint.sh /docker-entrypoint.sh
14+
RUN chmod +x /docker-entrypoint.sh
815

916
# Create directory for static files (optional)
1017
RUN mkdir -p /usr/share/nginx/html
1118

1219
EXPOSE 80
1320

21+
ENTRYPOINT ["/docker-entrypoint.sh"]
1422
CMD ["nginx", "-g", "daemon off;"]

tools/reverse-proxy/README.md

Lines changed: 155 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,174 @@
11
# Nginx Reverse Proxy
22

3-
A basic nginx web server Docker configuration.
3+
A nginx reverse proxy configuration that routes requests to different backend services based on subdomain.
4+
5+
## Configuration
6+
7+
This reverse proxy is configured to forward requests to different ports based on subdomain. Each subdomain maps to a specific service defined in `docker-compose.yml`.
8+
9+
### Environment Variables
10+
11+
The domain used for subdomain routing can be configured using the `DOMAIN` environment variable. This allows you to use different domains for different environments (dev, test, prod).
12+
13+
**Default:** `sample-dev.com` (if `DOMAIN` is not set)
14+
15+
**Examples:**
16+
- Development: `DOMAIN=sample-dev.com`
17+
- Test: `DOMAIN=sample-test.com`
18+
- Production: `DOMAIN=sample-prod.com`
19+
20+
### Subdomain Routing
21+
22+
The following subdomains are configured (using `${DOMAIN}` as the base domain):
23+
24+
- `js-client-side.${DOMAIN}` → JavaScript SDK Client Side (port 3031)
25+
- `js-client-server.${DOMAIN}` → JavaScript SDK Client Server (port 3032)
26+
- `js-react.${DOMAIN}` → JavaScript SDK React Client Side (port 3034)
27+
- `server-side.${DOMAIN}` → Server Side Integration (port 3033)
28+
- `secure-signals-client-server.${DOMAIN}` → Google Secure Signals Client Server (port 3041)
29+
- `secure-signals-client-side.${DOMAIN}` → Google Secure Signals Client Side (port 3042)
30+
- `secure-signals-server-side.${DOMAIN}` → Google Secure Signals Server Side (port 3043)
31+
- `secure-signals-react.${DOMAIN}` → Google Secure Signals React Client Side (port 3044)
32+
- `prebid-client.${DOMAIN}` → Prebid Client Side (port 3051)
33+
- `prebid-client-server.${DOMAIN}` → Prebid Client Server (port 3052)
34+
- `prebid-secure-signals.${DOMAIN}` → Prebid Secure Signals Client Side (port 3061)
35+
36+
**Example with default domain (`sample-dev.com`):**
37+
- `js-client-side.sample-dev.com` → JavaScript SDK Client Side (port 3031)
38+
- `js-client-server.sample-dev.com` → JavaScript SDK Client Server (port 3032)
39+
- etc.
40+
41+
## Required Hosts File Configuration
42+
43+
To use the subdomain-based routing, you must add entries to your hosts file so that these subdomains resolve to localhost.
44+
45+
**Note:** Replace `sample-dev.com` with your configured `DOMAIN` value in the examples below.
46+
47+
### Windows
48+
49+
1. Open Notepad (or your preferred text editor) **as Administrator**
50+
- Right-click Notepad → "Run as administrator"
51+
- Or use PowerShell as Administrator
52+
53+
2. Open the hosts file:
54+
```
55+
C:\Windows\System32\drivers\etc\hosts
56+
```
57+
58+
3. Add the following entries at the end of the file:
59+
```
60+
127.0.0.1 js-client-side.sample-dev.com
61+
127.0.0.1 js-client-server.sample-dev.com
62+
127.0.0.1 js-react.sample-dev.com
63+
127.0.0.1 server-side.sample-dev.com
64+
127.0.0.1 secure-signals-client-server.sample-dev.com
65+
127.0.0.1 secure-signals-client-side.sample-dev.com
66+
127.0.0.1 secure-signals-server-side.sample-dev.com
67+
127.0.0.1 secure-signals-react.sample-dev.com
68+
127.0.0.1 prebid-client.sample-dev.com
69+
127.0.0.1 prebid-client-server.sample-dev.com
70+
127.0.0.1 prebid-secure-signals.sample-dev.com
71+
```
72+
73+
4. Save the file
74+
75+
5. Flush DNS cache (run in PowerShell as Administrator):
76+
```powershell
77+
ipconfig /flushdns
78+
```
79+
80+
### macOS / Linux
81+
82+
1. Open the hosts file with sudo:
83+
```bash
84+
sudo nano /etc/hosts
85+
```
86+
(or use `vim`, `vi`, or your preferred editor)
87+
88+
2. Add the following entries:
89+
```
90+
127.0.0.1 js-client-side.sample-dev.com
91+
127.0.0.1 js-client-server.sample-dev.com
92+
127.0.0.1 js-react.sample-dev.com
93+
127.0.0.1 server-side.sample-dev.com
94+
127.0.0.1 secure-signals-client-server.sample-dev.com
95+
127.0.0.1 secure-signals-client-side.sample-dev.com
96+
127.0.0.1 secure-signals-server-side.sample-dev.com
97+
127.0.0.1 secure-signals-react.sample-dev.com
98+
127.0.0.1 prebid-client.sample-dev.com
99+
127.0.0.1 prebid-client-server.sample-dev.com
100+
127.0.0.1 prebid-secure-signals.sample-dev.com
101+
```
102+
103+
3. Save and exit
104+
105+
4. Flush DNS cache (if needed):
106+
```bash
107+
# macOS
108+
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
109+
110+
# Linux (systemd-resolved)
111+
sudo systemd-resolve --flush-caches
112+
```
4113

5114
## Usage
6115

7-
### Build the image
116+
### Using Docker Compose (Recommended)
117+
118+
When using `docker-compose.yml` from the project root, the reverse proxy will automatically connect to other services on the same Docker network:
119+
120+
**Default domain (sample-dev.com):**
121+
```bash
122+
docker-compose up reverse-proxy
123+
```
124+
125+
**Custom domain:**
126+
```bash
127+
DOMAIN=sample-test.com docker-compose up reverse-proxy
128+
```
129+
130+
**Or set in your `.env` file:**
131+
```bash
132+
DOMAIN=sample-prod.com
133+
```
134+
135+
Then run:
136+
```bash
137+
docker-compose up reverse-proxy
138+
```
139+
140+
### Standalone Build and Run
141+
142+
#### Build the image
8143
```bash
9144
docker build -t nginx-reverse-proxy .
10145
```
11146

12-
### Run the container
147+
#### Run the container
148+
149+
**Default domain:**
13150
```bash
14151
docker run -d -p 80:80 --name nginx-proxy nginx-reverse-proxy
15152
```
16153

17-
### Run with custom static files
154+
**Custom domain:**
18155
```bash
19-
docker run -d -p 80:80 -v /path/to/your/html:/usr/share/nginx/html --name nginx-proxy nginx-reverse-proxy
156+
docker run -d -p 80:80 -e DOMAIN=sample-test.com --name nginx-proxy nginx-reverse-proxy
20157
```
21158

22-
## Configuration
159+
**Note:** When running standalone, you'll need to ensure the backend services are accessible. You may need to modify the `proxy_pass` directives in `default.conf.template` to use `host.docker.internal` or the appropriate Docker network hostname.
160+
161+
## Customization
23162

24-
Edit `default.conf` to customize the nginx configuration. The default configuration serves static files from `/usr/share/nginx/html`.
163+
Edit `default.conf.template` to customize the nginx configuration:
164+
- Add or remove server blocks for different subdomains
165+
- Modify subdomain names in the `server_name` directives (use `${DOMAIN}` for the domain variable)
166+
- Adjust proxy headers as needed
167+
- Add additional location blocks for specific routes
25168

26-
To use as a reverse proxy, uncomment and modify the proxy_pass section in `default.conf`.
169+
**Important:** After modifying `default.conf.template`, rebuild the Docker image:
170+
```bash
171+
docker-compose build reverse-proxy
172+
docker-compose up -d reverse-proxy
173+
```
27174

tools/reverse-proxy/default.conf

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)