40

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.
Oli
  • 293,335
Newbie
  • 570
  • 1
  • 5
  • 11
  • 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 09: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 09:09
  • @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 09: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
  • @Oli yep that solved my problem, apache's index file in var/www thank you, btw i already looked in multiple questions before posting this :P so it's not a duplicate my problem was different – Newbie Jun 29 '15 at 10:38

3 Answers3

43

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
Oli
  • 293,335
  • 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
  • ls -lah /etc/nginx/sites-available/default says "No such file or directory" so my problem must be different. – Ryan Aug 05 '20 at 19:47
  • If you check the response headers in your browser dev tools you should see Server: nginx/1.18.0 (Ubuntu) or similar so you can see that nginx rather than apache is serving up the page – jx12345 Nov 02 '21 at 19:50
6

Both Nginx and Apache are referring to the /var/www HTML file.

Run this command and refresh the page:

mv /var/www/html/index.html index.html_bkp
1
sudo service nginx configtest

Make sure the config is good before reloading!

sudo service nginx reload