Use Nginx in Docker as a reverse proxy serving static files and proxying API requests internally.
Nginx Reverse Proxy
# nginx.conf
http {
upstream backend { server api:3000; }
server {
listen 80;
location / {
root /usr/share/nginx/html;
try_files $uri $uri/ /index.html;
}
location /api/ {
proxy_pass http://backend/;
proxy_set_header Host $host;
}
}
}
# docker-compose.yml
services:
nginx:
image: nginx:alpine
ports: ["80:80"]
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
depends_on: [api]
api:
build: ./api
expose: ["3000"] # internal only