Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop nginx from using port 80

Tags:

linux

nginx

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).

like image 948
Kurt Peek Avatar asked Feb 09 '17 11:02

Kurt Peek


People also ask

Why does Nginx use port 80?

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.


2 Answers

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.

like image 148
Luca Fagioli Avatar answered Sep 19 '22 15:09

Luca Fagioli


Open /etc/nginx/sites-available/default

nano /etc/nginx/sites-available/default

Change port 80 in there to something else and save your changes

like image 20
Tono Nam Avatar answered Sep 20 '22 15:09

Tono Nam