90

I went through some manuals and I didn't understand yet. How do I disable autostart nginx service?

2 Answers 2

117

Try this command:

sudo update-rc.d -f nginx disable
7
  • 1
    I tried sudo update-rc.d -f nginx disable. What is the difference between them?
    – Alex Malex
    Aug 17, 2012 at 14:15
  • 1
    The difference is that disable is better! :) You got me. It effectively 'makes dpkg aware of your preference to prevent the startup scripts from being executed (because dpkg runs update-rc.d too)'. Credit to @Lekensteyn for the explanation.
    – SirCharlo
    Aug 17, 2012 at 14:19
  • 1
    I already run disable and then remove. How can I undo it?
    – Alex Malex
    Aug 17, 2012 at 14:32
  • Umm.. You want to enable autostart now?
    – SirCharlo
    Aug 17, 2012 at 14:34
  • 4
    sudo update-rc.d nginx defaults; sudo update-rc.d -f nginx disable
    – SirCharlo
    Aug 17, 2012 at 15:26
59

Update:
I made changes to supports more distributions:

use this:

sudo systemctl disable nginx

It will disable it and if you like to stop running service use this:

sudo systemctl stop nginx

works on Ubuntu and any Systemd based distributions

4
  • 3
    it works on ububut 18.04 as well Oct 1, 2019 at 5:10
  • 1
    If you're going to use systemd style, use it for everything, don't have some weird mashup of using the service shim for some commands. That second one should just be sudo systemctl stop nginx. Sep 12, 2020 at 12:26
  • Also works on ububut 20.10 as well Mar 12, 2021 at 18:22
  • 1
    This approach is better.
    – EGurelli
    Oct 13, 2021 at 3:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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