Any good way to programmatically change nginx config file from python?

There is now nginx-conf, an NPM module that provides programmatic access to nginx configurations.


NGINX Inc started providing a library in 2017 that is a "quick and reliable way to convert NGINX configurations into JSON and back." It's called crossplan and you can get it with pip.

pip install crossplane

With this you can parse a file to JSON, deserialize, manipulate, serialize back to JSON, and then convert back to the NGINX config file format.


There seems to exist an augeas lens supporting at least a subset of the nginx config file syntax. Augeas also has Python bindings.


  1. https://www.npmjs.com/package/nginx-conf

  2. You might use the PyNginxConfig Parser. http://code.google.com/p/pynginxconfig/source/browse/pynginxconfig.py#208 This implementation is close to the original one.

  3. There is also ServerMgr. It's not really a parser, just allows for basic mappings.

  4. Last but not least, actually first, because based on pyparsing: https://github.com/fatiherikli/nginxparser

    pip install git+https://github.com/fatiherikli/nginxparser.git

Tags:

Python

Nginx