I’ve been dealing with this really annoying issue over the past few months in which a server reboot will cause the hostname to get screwed up. Essentially this is what will happen:
Normally the hostname will be server.mydomain.com. When the server is rebooted, the hostname is changed to just server with no domain attached. This causes some really annoying headaches, such as the inability to access cPanel due to certificate problems. When that happens, you need to fix the hostname and run a set of commands via SSH to get the certificate to reissue. The commands to fix the missing SSL issue are outlined here on Webtrunk.
While rebuilding a web server, I ran into this same annoying issue and finally decided I’d had enough of it. I’ve written a sort of fix for it that needs to run via a cronjob. Essentially what it does is checks the hostname of your server and if it’s not correct, it fixes it.
You’ll need to run it via a cronjob to make it effective. Using crontab -e, you would add something like this:
*/15 * * * * /path/to/hostnamecheck.sh
Obviously change /path/to/ to whatever the path is where you have stored the hostnamecheck.sh script. This will run every 15 minutes. If it’s wrong, it fixes it. If it’s not, it does nothing.
I am now off to do battle with NGINX. What a wonderful way to spend Christmas Eve.