Report this

What is the reason for this report?

My index.html file in Nginx automatically gets overwritten with the Nginx defaul index.html file for no reason.

Posted on November 5, 2016

I’m running Nginx on Ubuntu 14.04. I have my website installed in the default /usr/share/nginx/html directory. My website works fine for several days and then the system automatically overwrites my websites index.html file with the default Nginx “Welcome to nginx!” index.html file. I have to go back and copy my website’s index.html file again in order for my website to work. I’ve had my website up for a couple of weeks now and this has happened three times. My website will work for a few days and then my index.html file will get overwritten. There is no method to the madness. Does anyone know what might be causing this to happen?



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

By chance are you running automatic updates or any other automated process on your droplet? Hearing this, my first thought would be that the nginx index.html file is being cached somewhere causing you to see it in the browser but if you’re able to confirm that the file itself has changed via ssh then that would not be the case. Updates should not change the file but /usr/share is not always a location that apt packages will respect changes in. You may want to try copying your files to a different location and updating your configuration in /etc/nginx/sites-enabled/default to point to the new location.

The issue you’re encountering, where the custom index.html file in your Nginx server is getting overwritten by the default Nginx “Welcome to nginx!” page, is unusual and certainly not standard behavior. Here are a few potential causes and steps you can take to troubleshoot and resolve the issue:

1. Automatic Package Updates

Ubuntu systems sometimes have unattended upgrades enabled by default, which could update Nginx and overwrite your index.html file:

  • Check Unattended Upgrades: Review the configuration of unattended upgrades on your system. The configuration can usually be found in /etc/apt/apt.conf.d/50unattended-upgrades or similar files.

  • Manual Update Checks: You might have inadvertently updated Nginx through routine system updates that included a new version of Nginx, which could overwrite the file.

2. Cron Jobs

Check if there are any cron jobs set up that might be executing a script or command which overwrites your index.html:

  • Review Cron Jobs: Check both the system-wide cron jobs (/etc/crontab and /etc/cron.*/*) and user-specific ones (crontab -l).

3. Deployment Scripts

If you have any automated deployment scripts, continuous integration, or continuous deployment processes, ensure they’re not overwriting the file:

  • Check Deployment Configurations: Review any scripts or configurations for deployment tools that you’re using.

4. Server Management Software

If you use any web server management software or control panels (like Plesk, cPanel, etc.), ensure they are not set to reset or overwrite files:

  • Review Control Panel Settings: Some control panels have features for resetting to default configurations.

5. External Access

Ensure that no external parties have access to your server:

  • Review Access Logs: Check Nginx and system access logs for any unauthorized access.
  • Secure Server: Make sure your server is secure, with proper firewall settings, updated software, and strong authentication practices.

6. Filesystem Issues

Rare filesystem issues or disk errors could potentially cause file overwrites or loss:

  • Check Filesystem Health: Run filesystem checks (like fsck for Linux filesystems) to ensure there are no underlying issues.

7. Backup Strategy

As a preventive measure, set up a regular backup strategy for your website files:

  • Implement Backups: Use tools like rsync or backup software to regularly back up your website files.

Resolution Steps

  • Monitor: After checking the above, closely monitor your system to identify when the overwrite happens. This might help in correlating with any specific system events or cron jobs.

  • Change File Location: Consider serving your website from a different directory instead of the default Nginx directory. Update the Nginx configuration file to point to the new location. This might prevent overwriting if it’s related to Nginx defaults.

  • Consult Logs: System logs (/var/log/syslog, /var/log/auth.log, etc.) and Nginx logs (/var/log/nginx/error.log and /var/log/nginx/access.log) can provide clues.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.