
In this guide, we will walk you through the steps on how to completely remove Apache2 from your system and prevent it from showing up on Nginx. This is a common issue encountered by many system administrators when they switch from Apache2 to Nginx.
To remove Apache2 completely and prevent it from showing up on Nginx, you need to uninstall Apache2 and its related packages using the command sudo apt-get purge apache2 apache2-utils
. Additionally, you can edit or remove the default site files in /etc/nginx/sites-available/default
and modify the files in /var/www/
directory. Finally, delete the default site symlink /etc/nginx/sites-enabled/default
if you want to completely get rid of the default site. Remember to reload Nginx using sudo service nginx reload
after making any configuration changes.
Understanding the Issue
Even after uninstalling Apache2, you might still see an Apache site when accessing your IP address. This is because Nginx, by default, tries to serve the leftover site files from Apache2 located in the /var/www/
directory.
Removing Apache2 Completely
Before we proceed to the steps to resolve the issue, let’s ensure that Apache2 is completely removed from your system. Apache2 is a metapackage that is dependent on other packages. Therefore, even if you have removed Apache2, some related packages might still be present.
To check for any remaining Apache-related packages and remove them, use the following command:
sudo apt-get purge apache2 apache2-utils
Here, sudo
is used to run the command with root privileges, apt-get purge
is used to remove the packages along with their configuration files, and apache2 apache2-utils
are the packages that you want to remove.
Resolving the Issue
1. Editing or Removing the Default Site Files
The first option to resolve this issue is to navigate to the default site configuration file located at /etc/nginx/sites-available/default
and modify or delete it. This will prevent Nginx from serving the Apache default site files.
sudo nano /etc/nginx/sites-available/default
In the above command, sudo
is used to run the command with root privileges, nano
is a command-line text editor, and /etc/nginx/sites-available/default
is the path to the default site configuration file.
2. Modifying the Files in /var/www/
If you want to keep the default site files but want them to be served differently, you can modify the files in the /var/www/
directory.
sudo nano /var/www/html/index.html
Here, sudo
is used to run the command with root privileges, nano
is a command-line text editor, and /var/www/html/index.html
is the path to the default index file.
3. Deleting the Default Site Symlink
If you want to completely get rid of the default site, you can delete the symlink /etc/nginx/sites-enabled/default
. However, remember that you can restore it later if needed.
sudo rm /etc/nginx/sites-enabled/default
In this command, sudo
is used to run the command with root privileges, rm
is used to remove files or directories, and /etc/nginx/sites-enabled/default
is the path to the default site symlink.
Applying the Changes
After making any configuration changes, remember to reload Nginx to apply the changes. You can do this by using the following command:
sudo service nginx reload
Here, sudo
is used to run the command with root privileges, service
is used to run a System V init script, nginx
is the service that you want to control, and reload
is the action that you want to perform.
Conclusion
In this guide, we have covered how to completely remove Apache2 and prevent it from showing up on Nginx. By following these steps, you should now be able to successfully switch from Apache2 to Nginx without any issues. If you are still experiencing the issue, it’s possible that another server or process is running on your system. You can use tools like htop
to identify any running servers and investigate further.
To uninstall Apache2 completely from your system, you can use the command sudo apt-get purge apache2 apache2-utils
. This command will remove Apache2 along with its configuration files.
After uninstalling Apache2, you might still see an Apache site because Nginx tries to serve the leftover site files from Apache2 located in the /var/www/
directory by default. To resolve this, you can edit or remove the default site configuration file in /etc/nginx/sites-available/default
or modify the files in the /var/www/
directory.
Yes, you can keep the default site files in the /var/www/
directory but serve them differently. You can modify the files in the /var/www/
directory according to your requirements.