3

I'm running gunicorn and nginx on a Digital Ocean droplet. The issue I'm facing is that my config files for these services are at

/etc/nginx/sites-enabled/django

and

/etc/init/gunicorn.conf

while my code is at /src/my_project

My issue is, my source code is under source control. The config files within /etc/ aren't. This question, How do you deal with configuration files in source control?, says you should keep your config files in source control, but it doesn't explain how to configure them.

How do I include my nginx and gunicorn config files in source control with the rest of my django project, while still keeping the config files attached to nginx and gunicorn appropriately on the server? Thanks!

Community
  • 1
  • 1
YPCrumble
  • 20,703
  • 15
  • 86
  • 149

1 Answers1

3

You can add your nginx config file to your repository

mv /etc/nginx/sites-available/django /src/my_project/nginx/django
git add /src/my_project/nginx/django

Then create a symlink.

ln -s /src/my_project/nginx/django /etc/nginx/sites-enabled/django

You can do the same for your gunicorn config.

Alasdair
  • 253,590
  • 43
  • 477
  • 449
  • thanks - one question. Why did you use `sites-enabled` vs. `sites-available`? I tried with `sites-enabled` as you suggested but got the following error: `ln: failed to create symbolic link ‘/etc/nginx/sites-enabled/django’: File exists`. Tried creating the symlink to `sites-available` and I'm getting an Nginx 502 Bad Gateway error. – YPCrumble Apr 01 '15 at 21:19
  • actually the main question I have is I'm getting a 502 Bad Gateway error. Why do you use `sites-available` vs. `sites-enabled`? Should that be `sites-enabled`? – YPCrumble Apr 01 '15 at 21:30
  • Normally, you put the config files in the `sites-available` directory, then create a symlink to that file in `sites-enabled`. That way, you can disable the site by removing the symlink, without deleting the file. If you're getting the `File exists` error, you need to remove the file before creating the symlink (make sure you have a copy somewhere else first!). See [this question](http://serverfault.com/questions/83508/purpose-of-debian-sites-available-and-sites-enabled-dirs) for more explanation about `sites-available` and `sites-enabled`. – Alasdair Apr 01 '15 at 23:13
  • thanks for your help. Fixed Nginx. On the Gunicorn front, I've run into this issue: http://stackoverflow.com/questions/29401736/symlink-causing-unknown-job-gunicorn-error?lq=1 At first Gunicorn wouldn't restart at all, and I applied this fix: http://serverfault.com/a/224655/200183 Now, the process starts, but I'm getting `Failed to load resource: net::ERR_CONNECTION_REFUSED` and nothing obvious is showing up in either the Gunicorn or the Nginx logs. Do you know where I might search for a log that would help me fix the problem? Or know what the issue might be? – YPCrumble Apr 02 '15 at 15:17
  • I don't have any suggestions for your gunicorn problem. Hope you figure it out. – Alasdair Apr 02 '15 at 15:29