I Can't stop apache2. I want to use nginx, therefore,I want to remove/stop apache2 but I can't. I've tried all the methods on this Link , but when I refresh http://127.0.0.1/ i still see the apche2 there.
Ubuntu – How to stop Apache2 on Ubuntu 18.04
Apache2nginxuninstall
Related Solutions
Really there's two questions here, so I'll try to answer them both:
1. Why do Apache and Nginx display the same webpage?
Take a close look at your configuration files. You will see that they both load the same content:
Apache is loading (document root): /var/www/html
Nginx is loading (root): /var/www/html;
This means both servers will show the same content, as they are loading the same file(s). You can change your "root" directory to be two different locations by editing your configuration files.
eg apache:
<VirtualHost *:8080>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/apache
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
eg nginx:
server {
listen 8080;
server_name 127.0.0.1;
root /var/www/html/nginx;
index index.php index.html index.htm index.nginx-debian.html;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/html/nginx;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
You'd then need to make each directory and put a file in them:
mkdir /var/www/html/nginx
mkdir /var/www/html/apache
And put content into each of these folders. It's also worth checking the permissions of each folder are appropriate for the web server to access them.
2. How do I check to see if Apache has stopped and Nginx has started
There's a simple way to check the status of each service. Assuming you're logged in as root:
service apache2 stop #Stop apache
service apache2 status #is apache still running?
You can also use the ps command to get the process list:
ps aux | grep -i apache
This effectively gets all running processes, and searches for any with the name apache.
You can then start nginx and check it's running:
service nginx start #start nginx
service nginx status #is nginx running?
(optionally another way to prove the process is running): ps aux | grep -i nginx
It's also possible to see which program is listening on which port:
netstat -ntlp
This will tell you the local address, port, and process name of everything listening for connections on your computer. You should see in this list either nginx or apache running with port 8080 (based on your configuration files) exposed.
Please stop nginx first then try it to remove:
sudo apt-get purge nginx nginx-common
Or
sudo apt-get remove nginx-core nginx-full nginx-light nginx-extras nginx-naxsi nginx-common
Best Answer
What you're seeing is the
index.html
file that was installed by Apache. Do not trust solely the Index page being served as an indicator of the Web Server being used!Just because you're seeing the Apache "default" page, doesn't mean that you're actually seeing Apache running, you're just seeing the 'default page' that was installed. Neither NGINX nor Apache will overwrite the
index.html
file in the default web root if it was already present (in an ideal situation), so whichever was present first is actually the one that installed theindex.html
file - it won't change just because you installed a different webserver.You can confirm this by doing:
sudo rm /var/www/html/index.html && echo "I am testing things!" | sudo tee /var/www/html/index.html
and then refreshing your browser - you'll see that it's different content at this point.If the nginx software at install time sees an index.html file already in the default webroot
/var/www/html/
, it is supposed to not overwrite it. This is normal, so users who use the default docroot for their websites don't lose their data.What we need to do is confirm what Web Server is actually in use.
Always use actual command line tools to verify the web server software in use.
Leveraging
sudo netstat -tulpn | grep :80
we can get an idea of what web server is in use:As you can see, this is an Apache2 web server listening on port 80.
Conversely, if the server is
nginx
you see something like this:You can also determine if it's Apache2 or NGINX running by checking the output of one of the following commands:
Depending on which of these provides output, you can determine which web server is actually in use.