I am looking for a way to change some config parameters dynamically before running NGINX. Perfectly by using command line parameters. I want to write a bash script that takes for example two parameters:

  • root directory of files to be served,
  • name of the php docker container to process php files.

These parameters are normally defined in config file:


files to be served:

root /usr/share/nginx/html/public;

php parser:

fastcgi_pass php:9000;

Since they are hardcoded I need to create a specific configuration for every project I want to run with NGINX. I want to avoid that and have one bash script that reads CLI parameters and starts NGINX with them.

I could not find any other NGINX CLI Parameters than these and did not find a suitable candidates to achieve my goal. Maybe there are other CLI parameters I could use, maybe I could use environmental variable inside default.conf so values of root and fastcgi_pass aren't hardcoded, or maybe there is a plugin that could provide additional CLI parameters to NGINX?

I'm running official Docker images of NGINX 1.15 and PHP-FPM 7.3 via my bash script that uses docker run commands to set everything up.

  • nginx configuration is far too complex to be done on the command line, so only a very few (simple) options are usable. You are free to write your own configuration generator to meet your specific needs, though, or better yet, use container-aware configuration management such as Ansible/Ansible Container. – Michael Hampton Apr 23 at 1:20

Your Answer

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

Browse other questions tagged or ask your own question.