19

I installed nginx then I installed apache2, after a while I removed apache2. After a couple of weeks I noticed something strange when I accessed http://localhost: nginx handles the request but when I type in my IP address or anyone in my network types in my IP, it results in an apache2 page loading saying it's correctly working.

I purged and removed Apache but I still can't get rid of this problem, tried reinstalling and purging again then restarting. Any ideas of what could be the problem?

PS my computer doesn't recognize apache2 as being installed in anyway and all Apache files and binaries are not found even when I manually search for them.

root@elite-HP-Pro3500-G2-MT-PC:/home/elite# whereis apache2
apache2:
root@elite-HP-Pro3500-G2-MT-PC:/home/elite# sudo service apache2 start
Failed to start apache2.service: Unit apache2.service failed to load: No such file or directory.
root@elite-HP-Pro3500-G2-MT-PC:/home/elite# sudo apt-get purge apache2 apache2-utils
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package 'apache2' is not installed, so not removed
Package 'apache2-utils' is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 19 not upgraded.
  • For technical reasons, the apache2 package is just a metapackage that depends on other packages. You have to remove related packages too to remove the binary. – Oli Jun 29 '15 at 9:08
  • i've searched /user/sbin and /user/bin and i can't find it, do you know other locations where the binary could be? @Oli – Newbie Jun 29 '15 at 9:09
  • See my answer on the question I closed this against. – Oli Jun 29 '15 at 9:10
  • @Oli i've already followed that tutorial to remove apache2 but it still exists somehow, and i've found that problem only occurs when i'm using anything other than the loopback (localhost) it will redirect towards apache2 but if i use a localhost nginx works – Newbie Jun 29 '15 at 9:12
  • Are you sure it's actually Apache serving it and not just the default site files (in /var/www) that ships with default Apache install, now being hosted by ngninx? That's what it sounds like. If not, I'd be tracking down what's running with htop and finding out which servers are running. – Oli Jun 29 '15 at 10:20
22

Even after you remove apache2 completely, you will still have its "default site" files sitting in /var/www/. By default, Nginx will attempt to serve these or its own version of these files for sites it cannot otherwise match. You can see this all in /etc/nginx/sites-available/default.

What you're seeing is by design, it was just unexpected.

To fix it, you can edit or remove the default site... Or alter the files in /var/www/ to better suit your needs. If you want rid of the default, you can delete /etc/nginx/sites-available/default. It's just a symlink so if you want to restore it, you can with:

sudo ln -s /etc/nginx/sites-{available,enabled}/default

And remember to reload after making configuration changes:

sudo service nginx configtest  # make sure the config is good before reloading!
sudo service nginx reload
  • 1
    Wow - never guessed that. Tried all sort of playing-around with Apache until I read this post! – Anupam Jun 29 '17 at 11:59

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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