How to use environment variables in Nginx with Docker-Compose?

Asked

Viewed 55 times

0

I have the following code snippet in my Nginx configuration file:

location /api/ {
    proxy_pass http://backend:$BACKEND_PORT/;
    proxy_http_version 1.1;
  }

And I have the following code snippet in my Docker-Compose.yml

frontend:
    image: nginx:1.19.3
    container_name: Frontend
    env_file: .env
    environment:
      BACKEND_PORT: ${BACKEND_PORT}
    volumes:
      - ./Client:/usr/share/nginx/html/
      - ./Client/nginx/default.conf:/etc/nginx/conf.d/default.conf
    depends_on:
      - backend
    ports:
      - ${NGINX_PORT}:80
    networks:
      - client
      - server

How do I make my Nginx defacult.conf configuration file recognize my $BACKEND_PORT environment variable ?

Obs? have I tried ${BACKEND_PORT}, also doesn’t work.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.