I'm trying to update nginx using sudo apt-get install nginx, but it is giving me an error message related to port 80 being occupied. When I run
sudo netstat -tlnp | grep 80
I get
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      6845/nginx      
tcp        0      0 127.0.0.1:8080          0.0.0.0:*               LISTEN      1919/config.ru  
tcp        0      0 0.0.0.0:8060            0.0.0.0:*               LISTEN      6845/nginx
Although I wasn't able to easily understand what each column means from the --help function, I suppose that in this example 6845 is the process ID of nginx. If I try to kill it using
sudo kill 6845
and run sudo netstat -tlnp | grep 80 again, I see
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      10130/nginx     
tcp        0      0 127.0.0.1:8080          0.0.0.0:*               LISTEN      1919/config.ru  
tcp        0      0 0.0.0.0:8060            0.0.0.0:*               LISTEN      10130/nginx
In other words, it seems like nginx has immediately started listening on port 80 again under a different process ID. How can I stop nginx from running? (I've also tried sudo systemctl stop nginx but to no avail).
It is used in high-traffic websites such as Netflix and Dropbox to deliver their content in a quick, reliable, and secure manner. By default, the Nginx HTTP server listens for inbound connections and connects to port 80, which is the default web port.
You need to explicitly define a listen parameter other than 80 for every server block in /etc/nginx/nginx.conf, otherwise nginx will silently use port 80 by default.
Also, adjust the configuration in /etc/nginx/conf.d/default.conf.
Open /etc/nginx/sites-available/default
nano /etc/nginx/sites-available/default
Change port 80 in there to something else and save your changes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With