How to reload nginx of remote server using cron as root user
Install sudo
on the remote server (if not already installed). Then configure it to allow ubuntu
user to execute service nginx reload
command as root
without password prompt. Something like the following in sudoers
file:
ubuntu ALL=(root) NOPASSWD: /usr/sbin/service nginx reload
And now to reload nginx you just run (from ubuntu
user):
sudo -n service nginx reload
If you start your nginx server as ubuntu
(ssh -i /home/ubuntu/key.pem" ubuntu@example.com:/etc/nginx
), you don't need to reload as root
.
You can send the reload signal to the current nginx process:
ssh -i /home/ubuntu/key.pem" ubuntu@example.com:/etc/nginx -s reload