# Nginx for Local Development

## Overview

The `docker-compose.nginx.yml` file provides an **optional** nginx container for local development. This is **NOT** used on AWS (which uses bare metal nginx).

## When to Use

Use nginx container when you want to access services via friendly domains locally:
- `http://amarmascotas.local.com` → amar
- `http://soleprint.local.com` → soleprint + services

## Setup

### 1. Generate Nginx Config

```bash
cd ../ctrl/server
./setup.sh --local
```

This creates `/tmp/core_room.conf` with your local domain routing.

### 2. Ensure /etc/hosts is configured

```bash
# Should already be there, but verify:
grep "127.0.0.1.*amarmascotas.local.com" /etc/hosts
grep "127.0.0.1.*soleprint.local.com" /etc/hosts
```

### 3. Stop bare metal nginx (if running)

```bash
sudo systemctl stop nginx
# Optional: disable so it doesn't start on boot
sudo systemctl disable nginx
```

### 4. Start services WITH nginx

```bash
cd ../ctrl
./start.sh --with-nginx
# OR manually:
cd ../soleprint
docker compose -f docker-compose.yml -f docker-compose.nginx.yml up -d
```

## Without Nginx (Default)

If you don't use nginx, services are accessed via ports:
- `http://localhost:3000` → amar frontend
- `http://localhost:8000` → amar backend
- `http://localhost:13000` → soleprint
- `http://localhost:13001` → artery
- `http://localhost:13002` → album
- `http://localhost:13003` → ward

The default `docker-compose.yml` exposes these ports, so it works either way.

## Switching Between Nginx and Direct Access

**To use nginx routing:**
```bash
# Stop direct port access
cd ../ctrl && ./stop.sh

# Start with nginx
./start.sh --with-nginx
```

**To go back to direct ports:**
```bash
# Stop nginx version
cd ../soleprint
docker compose -f docker-compose.yml -f docker-compose.nginx.yml down

# Start without nginx
cd ../ctrl && ./start.sh
```

## AWS Production

On AWS, **do NOT use** `docker-compose.nginx.yml`. The AWS setup uses bare metal nginx configured via `ctrl/server/setup.sh --production`.

## Troubleshooting

**Port 80 already in use:**
```bash
# Check what's using it
ss -tlnp | grep :80

# If it's nginx bare metal
sudo systemctl stop nginx

# If it's another container
docker ps | grep :80
docker stop <container_name>
```

**Config not found error:**
```bash
# Make sure you ran setup first
cd ../ctrl/server && ./setup.sh --local

# Verify config exists
ls -la /tmp/core_room.conf
```

**DNS not resolving:**
```bash
# Check /etc/hosts
cat /etc/hosts | grep local.com

# Test DNS
ping -c 1 amarmascotas.local.com
```
