0

How can I make system-specific variations in my nginx.conf file, so I can use the same file on both - my development machine and on the live server?

nginx.conf pseudo example:

if system == mac then
  user _www;
else # ubuntu
  user www-data;
end
  1. Can I set environment variables in Bash that nginx.conf can read? If so, what is the syntax for reading these?
  2. Can I use the nginx -g option to give nginx arguments? If so, what is the command line syntax for this, and the syntax for reading the arguments inside nginx.conf?

Sorry for asking, but the manual is sort of vague on these topics.

Gottlieb Notschnabel
  • 9,408
  • 18
  • 74
  • 116
forthrin
  • 2,709
  • 3
  • 28
  • 50
  • Don't think it's wise the go down that path. The two machines will be different in some ways. It's easy to copy things over that work fine for a Mac but maybe not on the linux box. I think this will give you more headaches then it's worth. – Bart Apr 18 '13 at 19:04
  • I get your points, but then you have to perform every single edit to the local file also on the server, which seems just as big a headache. – forthrin Apr 18 '13 at 19:14
  • It can be all in the little details. Consider the following (not saying it will affect you). You have successfully copied over your config and everything works. For some reason you felt like tweaking some settings on the live server. The next time you copy over your "dev" config those edits will be lost. Maybe without you noticing it. – Bart Apr 18 '13 at 19:39
  • I would never edit the server config directly, but edit it locally and sync it over. Provided I could reuse the file. – forthrin Apr 18 '13 at 19:45
  • You should have your deploy script generate the actual nginx conf from one filled with placeholders: http://stackoverflow.com/questions/15416957/using-variables-in-nginx-location-rules/15432888#15432888 Nginx doesn't do this - you need to write your own tool. – Danack Apr 18 '13 at 23:49
  • OK, I get it. This question is a duplicate, then. – forthrin Apr 19 '13 at 06:04
  • I think you can close it yourself as a duplicate then. – Danack Apr 19 '13 at 15:28

1 Answers1

0

nginx.conf seems to defy the idea of if's and variables, I ended up writing a small script that converts a dev.conf to live.conf as part of the deployment. The differences are minuscule, but necessary.

forthrin
  • 2,709
  • 3
  • 28
  • 50