NGINX reverse proxy using Docker container


Setting up basic NGINX reverse proxy using Docker container. Checkout vessel project on GitHub for some usage examples.

nginx.conf

Simple NGINX reverse proxy configuration. The configuration forwards the host header value to the node, adds NGINX generated request id and passes X-Forwarded-For http headers.

server {
    listen 80;

    location /weather/ {
        proxy_set_header Host $http_host;
        proxy_pass http://weather:8080/weather/api/;
        proxy_set_header X-Request-Id $request_id;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

Dockerfile

Create a Dockerfile to create an image with NGINX reverse proxy configuration. Below Dockerfile copies the configuration from local file to container’s NGINX configuration directory.

FROM nginx:1.15.6-alpine

LABEL maintainer="mail@mujahidk.com"

COPY ./nginx.conf /etc/nginx/conf.d/default.conf

docker-compose.yml

Create a Docker compose file to run NGINX and sample weather service application on another container.

version: "3"
services:
  gateway:
    build: api-gateway
    ports:
      - "80:80"
  weather:
    image: mujahidk/weather:develop

See also

MicroservicesDockerContainers