Are there any basic templating preprocessors that I can use for nginx configuration files?

I've been using nginx variables to simplify my templates for a few years now. It turns out this is apparently a "rather slow" way of doing things and that my static configuration should be static.

With this in mind I would like to change to a situation where I have a nginx.conf.template file (or something like that) which I can run a command against —on my server— to generate a real configuration file.

My requirements are really simple:

  • Simple variable substitution. So I can have [something like]:

    SITE=oli
    DOMAIN=oli.example.com
    ------
    server { server_name ##DOMAIN##; ssl on; ssl_certificate /web/##SITE##/ssl/##DOMAIN##.crt; ssl_certificate_key /web/##SITE##/ssl/##DOMAIN##.key;
    ...

    I have to stress that the syntax above is completely made up on the spot. Just an example of how I'd imagine doing this.

  • Includes. Pull a file in AND (that's super-extra-important) also perform substitution.

  • Something simple. I'm lazy and I hate configuration. m4 looks lovely and all but zomg, I don't want to learn a new language just to configure a server. I'd rather just set the nginx manually if that's the trade-off.

This isn't specific to nginx, but that's what I'm using it for here. I'm just looking for a nice, simple command-line templating preprocessor. What have we got?

Reset to default

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like