5

I keep forgetting to reload nginx settings, sudo service nginx reload, while working on / experimenting / learning the config files, nginx (and other included config files).

Is there a way of achieving this, that nginx reloads configuration files, after any of the changes below:

  • /etc/nginx/nginx.conf
  • /etc/nginx/sites-available/ (any changes, deletion, creation of files)
  • /etc/nginx/sites-enabled/ (any changes, deletion, creation of files)

You may think it's just silly/stupid that I forget to reload, but while being new and actually learning and experimenting, there is really enough to keep track of.

1

2 Answers 2

4

Use a configuration management system to deploy these changes, and include a trigger to automatically restart services whose config files have changed.

It's very much worth getting into the habit of using CM now while you're learning, as it'll be much harder to un-learn bad habits later on in your career.

To get you started, here's a simple ansible playbook that will deploy an nginx config file to your server and then restart nginx if anything changed:

---
- hosts: web
  sudo: yes

  tasks:
    - name: Install packages
      apt: state=installed install_recommends=no name={{ item }}
      with_items:
        - nginx

    - name: Deploy nginx config file
      copy: src=nginx.conf dest=/etc/nginx/nginx.conf
      notify: restart nginx

  handlers:
    - name: restart nginx
      service: name=nginx state=restarted

Save that text into a file like foo.yml. You'll also need an inventory file to tell ansible what host(s) to run these commands on. Create a hosts file with contents like:

[web]
servername.example.com

Save your playbook, the inventory file, and your nginx.conf in the same directory.

Then you can apply the playbook:

$ ansible-playbook foo.yml -i hosts -K

After issuing that command, you'll be asked for your sudo password. Provide it, and then the playbook will run.

4
  • I'm always up for learning, though I am more than normally challenged right now ;) Could you point me in a useful direction, perhaps a specific tool, so I won't drown, because I'm pretty close already. Jul 7, 2015 at 13:08
  • 1
    Ansible is what I recommend to get started.
    – EEAA
    Jul 7, 2015 at 13:09
  • @MadsSkjern I just added a simple ansible example to get you started.
    – EEAA
    Jul 7, 2015 at 14:51
  • I'm sorry, but it will take some days before I can get to try this out. Jul 8, 2015 at 12:14
0

Obviously you want to have a CM(Configuration Management System),and Ansible is capalbe of automating ap p deployment.

I think CI(Continuous Integration) or CD(Continuous Deployment) can also meet your needs.use git+CI/CD+VM you can test your service easily.Some services you can try it:

Shippable, Circle CI, GitLab CI.

2
  • Also think of Chef
    – sebix
    Jul 7, 2015 at 20:14
  • Yes ,and puppet is not a bad idea.
    – Peng Feng
    Jul 8, 2015 at 0:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .