I try to setup nginx as a load balancer. The configuration is just a file with a lot of constrains so I need a validation. There is no online validation service, as e.g. CoreOS has, and I don’t want to install nginx on my laptop as I work on a distributed app.
Docker is right approach for me. Let say I have following config:
In short, I’m going to pass nginx config to running nginx instance and look to the logs.
Put you nginx.config to the temp and start the docker image:
sudo docker run –name nginx -v /tmp/nginx.config:/etc/nginx/nginx.conf:ro -d nginx
It uses volume mapping so the command just starts a new docker container and mounts a local /tmp/nginx.config to the given in-container path. You can obviously change the volume path to your personal path. Is it working or not? Look at logs.
sudo docker logs nginx
If there is no entry, your file is fine. In the case of an error, you can see something like this:
2016/01/08 11:37:31 [emerg] 1#1: unexpected “}” in /etc/nginx/nginx.conf:44
nginx: [emerg] unexpected “}” in /etc/nginx/nginx.conf:44
Note that if you want to validate the file again just stop, remove and then start container again, e.g.:
sudo docker stop nginx
sudo docker rm nginx