My colleague Jan showed me how to do this so I'm going to blog about it to not forget and perhaps by being here other people might be able to search and find the solution too. I installed nginx because I wanted to play with it as an alternative to apache on my laptop. Now I've played enough and I'm going to want to remove it. My first attempt didn't work:

peterbe@trillian:~ $ sudo apt-get --purge remove nginx
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
0 upgraded, 0 newly installed, 1 to remove and 116 not upgraded.
1 not fully installed or removed.
Need to get 0B of archives.
After unpacking 528kB disk space will be freed.
Do you want to continue [Y/n]?
(Reading database ... 242827 files and directories currently installed.)
Removing nginx ...
Stopping nginx: invoke-rc.d: initscript nginx, action "stop" failed.
dpkg: error processing nginx (--purge):
 subprocess pre-removal script returned error exit status 1
Starting nginx: invoke-rc.d: initscript nginx, action "start" failed.
dpkg: error while cleaning up:
 subprocess post-installation script returned error exit status 1
Errors were encountered while processing:
E: Sub-process /usr/bin/dpkg returned an error code (1)

I tried this both before and after having stopped and started nginx. Nothing worked. The trick is to fiddle with the init script /etc/init.d/nginx and insert a exit 0 at the top so that it now starts like this:

exit 0

Once saved and you try apt-get --purge remove nginx it will work. It might warn you that /var/log/nginx aren't removed because they're not empty but you can safely remove them manually unless you want to keep them.

Parand - 29 March 2008 [«« Reply to this]
What was your general impression of nginx and what made you decide to remove it? I've been meaning to give it a try as well, would be interested in hearing your experiences.
Peter Bengtsson - 31 March 2008 [«« Reply to this]
I didn't give it a fair test. I just wanted to see if I could get Zope to run behind it. With the kind of work I do, the bottleneck won't be in the fronting server so I wouldn't be able to say if nginx is better than apache.
Peter Bengtsson - 10 April 2008 [«« Reply to this]
Watch this video:
fast forward to about 8 minutes in when he talks about the difference between Apache and Nginx. You'll be impressed by the difference. (hint: Nginx rocks!)
Anonymous - 22 September 2008 [«« Reply to this]
Yes, indeed it rocks
Excellent, vraiment
I have removed Apache
Bar Chiu - 02 June 2009 [«« Reply to this]
Thanks for the tip!
ray - 11 November 2009 [«« Reply to this]
can any 1 tell me how i can remove nginx from my laptop
e - 09 April 2011 [«« Reply to this]
I seemed to have uninstalled NGINX but since i installed it i have no internet connection. I think that's because i only have one nic and the webserver was monopolizing port 80. however, not it's uninstalled and i still have no internet.
Sniper296 - 08 September 2011 [«« Reply to this]
Thankyou, I was having problems getting the configuration files (/etc/nginx/) back after accidentily deleting them.
I used
apt-get --purge remove ^nginx
apt-get install nginx
and reinstalled and they returned. - 01 July 2012 [«« Reply to this]
how to I get this off my computer - it pops up on my search screen
Anonymous - 07 July 2012 [«« Reply to this]
For us lay peeps, can you please give me the step by step instructions. I just use the computer, I don't know the hardware and software programmings. Thank you!
Ismail Rachdaoui - 14 February 2015 [«« Reply to this]
Hi, there is an other tricks to remove nginx, nginx is a metapackage, so to remove it you should first remove all of its dependencies, to proceed just run "sudo apt-cache show nginx" this will display all nginx's related packages, in my case it was nginx-full nginx-ligh, then run apt-get remove to remove theme ''sudo apt-get remove nginx-full nginx-ligh' ...

Your email will never ever be published