Repository navigation
nginx: Verify that configuration is syntactically correct - #17208
Conversation
|
@roblabla, thanks for your PR! By analyzing the annotation information on this pull request, we identified @domenkozar, @roconnor and @lethalman to be potential reviewers |
|
This is very much appreciated. However, it needs to be an option as it will fail for a lot of people. For instance my nginx configuration depends on certificates that are generated by ACME before Nginx starts. Running this on a NixOS machine will not work when ACME (or its dummy) has not ran before. Nginx and ACME can only run after the configuration has been built. In addition, tools like nixops and building VMs on a machine that isn't the target will also fail when Nginx is referring to files outside of #15906 covers some of the problems around avoiding stopping/starting Nginx with an invalid configuration. |
|
But if you look at the implementation it ignores exit code but just checks On Sat, Jul 23, 2016, 21:20 Bob van der Linden [email protected]
|
|
The implementation just verifies nginx sends a "syntax is ok" message. I have observed that this message is always sent (assuming syntax is OK), even if nginx fails to load the SSL files 'n stuff. I'm not 100% sure that it is always the I do not know what happens in case of missing I'll admit this is a fairly bandaid solution though. I wish |
|
Aah, it took me a while to see what you meant. But after running Sorry for the confusion. This look good. 👍 |
|
It seems that On my computer, running |
|
This breaks on nixops deployments: The path |
|
@globin i'll revert it and lets get your PR in first. we can then make this check optional (disabled by default ofcourse) |
|
No, don't make it optional. This sort of check fundamentally does not work, as we discovered years ago with the equivalent for Apache. |
|
Well, I personally need this kind of check. Being able to optionally enable it with something like If you think that's OK, I can make a PR for this right now ? |
|
The only viable way is to do the check outside of the build, but before switching to the new configuration. Having a pre-switch hook to prevent switching to a new configuration has been discussed, but I don't think we have it yet... |
|
What I have done works (if only for the fact that the test isn't perfect). By making the derivation that puts the config in the store fail, we make the whole build fail, which prevents switching. Outside of the syntax test being imperfect due to nginx trying to load SSL files in a syntax test..., what's the problem with my approach ? |
|
It doesn't work at all as long as you don't build on the same machine you're running nginx on, which we for example never do, either the machine config is build on hydra or the machine is deployed via nixops. |
|
Which is why having it opt-in (requiring users to do |
|
can someone sketch the implementation of a pre-switch hook? Edit: question then becomes how do i get the new store directory values with |
Motivation for this change
Making mistakes on a daily basis to the nginx config, I've made my website fall way too often due to a missing semicolon. With this change, the configFile writeText will fail if nginx -t doesn't report "syntax is ok". Note that
nginx -talso checks if the files referenced in the config exists. However, I had to disable those checks since the user running the build (nixbld) doesn't necessarely have access to the files used by nginx (root for the master process).If there is a way to run the checks under the correct user, that'd be even better. I haven't found a way to do that though.
Things done
(nix.useChroot on NixOS,
or option
build-use-chrootinnix.confon non-NixOS)
nix-shell -p nox --run "nox-review wip"./result/bin/)