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.
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:
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 ahosts
file with contents like:Save your playbook, the inventory file, and your nginx.conf in the same directory.
Then you can apply the playbook:
After issuing that command, you'll be asked for your sudo password. Provide it, and then the playbook will run.
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.