added sample both local docker and system ngins options
This commit is contained in:
35
cfg/sample/soleprint/docker-compose.nginx.yml
Normal file
35
cfg/sample/soleprint/docker-compose.nginx.yml
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
# Nginx Reverse Proxy for Docker-based Local Development
|
||||||
|
#
|
||||||
|
# Usage:
|
||||||
|
# # Start all services including nginx:
|
||||||
|
# docker compose -f docker-compose.yml -f docker-compose.nginx.yml up -d
|
||||||
|
#
|
||||||
|
# # Or start nginx separately after other services:
|
||||||
|
# docker compose -f docker-compose.nginx.yml up -d
|
||||||
|
#
|
||||||
|
# Routes:
|
||||||
|
# - sample.spr.local.ar -> frontend with sidebar injection
|
||||||
|
# - sample.local.ar -> frontend without sidebar
|
||||||
|
#
|
||||||
|
# Note: Requires /etc/hosts entries:
|
||||||
|
# 127.0.0.1 sample.spr.local.ar sample.local.ar
|
||||||
|
|
||||||
|
name: ${DEPLOYMENT_NAME}_nginx
|
||||||
|
|
||||||
|
services:
|
||||||
|
nginx:
|
||||||
|
image: nginx:alpine
|
||||||
|
container_name: ${DEPLOYMENT_NAME}_nginx
|
||||||
|
ports:
|
||||||
|
- "80:80"
|
||||||
|
volumes:
|
||||||
|
- ./nginx/local.conf:/etc/nginx/conf.d/default.conf:ro
|
||||||
|
networks:
|
||||||
|
- default
|
||||||
|
depends_on:
|
||||||
|
- soleprint
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
|
networks:
|
||||||
|
default:
|
||||||
|
name: ${NETWORK_NAME}
|
||||||
72
cfg/sample/soleprint/nginx/local.conf
Normal file
72
cfg/sample/soleprint/nginx/local.conf
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
# Sample Room - Nginx Config for Docker
|
||||||
|
#
|
||||||
|
# This config uses docker service names (soleprint, frontend, backend)
|
||||||
|
# which resolve within the docker network.
|
||||||
|
|
||||||
|
# sample.spr.local.ar - frontend with soleprint sidebar
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name sample.spr.local.ar;
|
||||||
|
|
||||||
|
# Soleprint routes - sidebar API and assets
|
||||||
|
location /spr/ {
|
||||||
|
proxy_pass http://soleprint:8000/;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Backend API (uncomment if your app has a backend)
|
||||||
|
# location /api/ {
|
||||||
|
# proxy_pass http://backend:8000/api/;
|
||||||
|
# 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;
|
||||||
|
# }
|
||||||
|
|
||||||
|
# Frontend with sidebar injection
|
||||||
|
location / {
|
||||||
|
proxy_pass http://frontend:80;
|
||||||
|
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_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection "upgrade";
|
||||||
|
proxy_set_header Accept-Encoding "";
|
||||||
|
|
||||||
|
# Inject sidebar CSS and JS into head
|
||||||
|
sub_filter '</head>' '<link rel="stylesheet" href="/spr/sidebar.css"><script src="/spr/sidebar.js" defer></script></head>';
|
||||||
|
sub_filter_once off;
|
||||||
|
sub_filter_types text/html;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# sample.local.ar - frontend without sidebar (direct access)
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name sample.local.ar;
|
||||||
|
|
||||||
|
# Backend API (uncomment if your app has a backend)
|
||||||
|
# location /api/ {
|
||||||
|
# proxy_pass http://backend:8000/api/;
|
||||||
|
# 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://frontend:80;
|
||||||
|
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_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection "upgrade";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -57,9 +57,52 @@ Next.js and other streaming SSR frameworks may not include `</body>` in the init
|
|||||||
|
|
||||||
## Nginx Configuration
|
## Nginx Configuration
|
||||||
|
|
||||||
### For Local Development (system nginx)
|
There are two options for local development:
|
||||||
|
|
||||||
Each room needs entries in `/etc/nginx/sites-enabled/`:
|
### Option 1: Docker Nginx (Recommended for portability)
|
||||||
|
|
||||||
|
Each room includes a docker-compose.nginx.yml that runs nginx in a container.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Add to /etc/hosts
|
||||||
|
127.0.0.1 sample.spr.local.ar sample.local.ar
|
||||||
|
|
||||||
|
# Start room with nginx
|
||||||
|
cd gen/<room>/soleprint
|
||||||
|
docker compose -f docker-compose.yml -f docker-compose.nginx.yml up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
The nginx config in `cfg/<room>/soleprint/nginx/local.conf` uses docker service names:
|
||||||
|
|
||||||
|
```nginx
|
||||||
|
location /spr/ {
|
||||||
|
proxy_pass http://soleprint:8000/;
|
||||||
|
}
|
||||||
|
|
||||||
|
location / {
|
||||||
|
proxy_pass http://frontend:80;
|
||||||
|
# ... sub_filter for sidebar injection
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Pros**: Portable, no system dependencies, isolated per room
|
||||||
|
**Cons**: Only one room can use port 80 at a time
|
||||||
|
|
||||||
|
### Option 2: System Nginx (For running multiple rooms)
|
||||||
|
|
||||||
|
If you need multiple rooms running simultaneously, use your system's nginx.
|
||||||
|
|
||||||
|
1. Install nginx: `sudo apt install nginx`
|
||||||
|
|
||||||
|
2. Add hosts entries for all rooms:
|
||||||
|
```
|
||||||
|
# /etc/hosts
|
||||||
|
127.0.0.1 amar.spr.local.ar amar.local.ar
|
||||||
|
127.0.0.1 dlt.spr.local.ar dlt.local.ar
|
||||||
|
127.0.0.1 sample.spr.local.ar sample.local.ar
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Create config in `/etc/nginx/sites-enabled/spr_local.conf`:
|
||||||
|
|
||||||
```nginx
|
```nginx
|
||||||
# room.spr.local.ar - app with sidebar
|
# room.spr.local.ar - app with sidebar
|
||||||
@@ -79,7 +122,10 @@ server {
|
|||||||
# Backend API (if applicable)
|
# Backend API (if applicable)
|
||||||
location /api/ {
|
location /api/ {
|
||||||
proxy_pass http://127.0.0.1:BACKEND_PORT/api/;
|
proxy_pass http://127.0.0.1:BACKEND_PORT/api/;
|
||||||
# ... headers
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Frontend with sidebar injection
|
# Frontend with sidebar injection
|
||||||
@@ -102,24 +148,14 @@ server {
|
|||||||
server {
|
server {
|
||||||
listen 80;
|
listen 80;
|
||||||
server_name room.local.ar;
|
server_name room.local.ar;
|
||||||
# ... same as above but without sub_filter
|
# ... same locations but without sub_filter in / block
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### For Docker/AWS (nginx container)
|
4. Reload nginx: `sudo nginx -t && sudo systemctl reload nginx`
|
||||||
|
|
||||||
The nginx config lives in `cfg/<room>/soleprint/nginx/local.conf` and uses docker service names instead of localhost ports:
|
**Pros**: Multiple rooms on port 80 via different hostnames
|
||||||
|
**Cons**: Requires system nginx, manual config updates
|
||||||
```nginx
|
|
||||||
location /spr/ {
|
|
||||||
proxy_pass http://soleprint:8000/spr/;
|
|
||||||
}
|
|
||||||
|
|
||||||
location / {
|
|
||||||
proxy_pass http://frontend:3000;
|
|
||||||
# ... sub_filter same as above
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Port Allocation
|
## Port Allocation
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user