Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get .conf.template files to work with env variables/file. #2424

Open
Jannick94 opened this issue Apr 23, 2024 · 2 comments
Open

Can't get .conf.template files to work with env variables/file. #2424

Jannick94 opened this issue Apr 23, 2024 · 2 comments

Comments

@Jannick94
Copy link

Can't get .conf.template files to work with env variables/file

I'm having an issue getting .conf.template files to generate a .conf file within the /etc/nginx/conf.d directory.

I have the following docker-compose.yml file:

# docker-compose.yml

version: '3.8'

services:
  nginx-proxy:
    image: nginxproxy/nginx-proxy:1.5
    container_name: nginx-proxy
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    environment:
      - TRUST_DOWNSTREAM_PROXY=false
      - KEEPALIVE_REQUESTS=${KEEPALIVE_REQUESTS}
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro
      - ./certs:/etc/nginx/certs
      - ./config/custom.conf.template:/etc/nginx/templates/custom.conf.template
    networks:
      - nginx-proxy-network

networks:
  nginx-proxy-network:
    name: nginx-proxy-network

Within the mounted config folder I have the following custom.conf.template file and .env file

# custom.conf.template
keepalive_requests ${KEEPALIVE_REQUESTS};
# .env
KEEPALIVE_REQUESTS=9999

When I start the proxy container using docker compose up and navigate to the /etc/nginx/templates folder to see if everything got mounted correctly I get the following output:

➜  docker git:(develop) ✗ docker exec -it nginx-proxy bash
root@d9d62440ba84:/app# cd /etc/nginx/templates
root@d9d62440ba84:/etc/nginx/templates# ls
custom.conf.template
root@d9d62440ba84:/etc/nginx/templates# cat custom.conf.template 
keepalive_requests ${KEEPALIVE_REQUESTS};

The issue

However when after that I navigate to the /etc/nginx/conf.d folder, I just see the default.conf file. I expected to see custom.conf aswell.

root@d9d62440ba84:/etc/nginx/templates# cd /etc/nginx/conf.d
root@d9d62440ba84:/etc/nginx/conf.d# ls
default.conf

Using the base nginx container does work

I also tried this exact same setup using a base nginx:1.25.4 image, and everything worked just fine.
It seems as if the parent nginx image entrypoints (mainly https://github.com/nginxinc/docker-nginx/blob/master/stable/debian/20-envsubst-on-templates.sh) arent triggered correctly/overridden by something the proxy does?

Thanks! 🙏🏻

@SchoNie
Copy link
Contributor

SchoNie commented Apr 23, 2024

The entrypoint of nginx-proxy is different so your substitutes are not processed.

But I think your keepalive_request tweak is very easy to implement. I am using something similar to adjust a global setting.

Map your extra config file (custom.conf.template) to the container as custom.conf in the /etc/nginx/conf.d/ (nginx automatically loads all files ending in .conf in this folder)

    volumes:
      - ./config/custom.conf.template:/etc/nginx/conf.d/custom.conf

Your custom.conf.template should contain the value, no env stuff:

# custom.conf.template
keepalive_requests 9999;

Verify your extra conf is loaded: sudo docker exec nginx-proxy nginx -T (the custom config should display somewhere after the mime types)

@buchdag
Copy link
Member

buchdag commented May 4, 2024

@Jannick94 I ran into the same thing a few months ago.

Ideally I'd like nginx-proxy to execute the same startup scripts as the upstream nginx images, without re-implementing their entrypoint. I'll see what I can do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants