Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The default nginx package creates a symlink named default in the sites-enabled dir, which points to a default config file in sites-available. I'm currently creating a package for an app that sits on top of Nginx, and I want to remove or move away the default symlink, and replace it with the config file from my package. Ideally, in the event that my package is removed, the original default symlink will be restored.

I've been reading the manpage and examples of dpkg-divert, but I don't quite see that it can do this. Is this achievable with dpkg-divert, or do I have to think of another way?

share|improve this question
up vote 4 down vote accepted

If you want to divert a file owned by another package:

  • In your preinst, divert the file away.

    dpkg-divert --add --package $your_package_name --rename \
       --divert /etc/nginx/sites-available/default.disabled \
  • In your postrm, divert the file back.

    dpkg-divert --remove --package $your_package_name --rename \

This won't work for the symlink /etc/nginx/sites-enabled/default, because it's created by the nginx package's postinst rather than being part of the package. Since the symlink is part of the package, you can just rename it with mv. I don't know if this is compliant with the Debian packaging policy; if this matters to you, as this is a rather specialized question, I recommend searching or asking on debian-devel.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.