简体   繁体   中英

How to stop nginx from using port 80

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

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

I managed to solve the problem by going to 127.0.0.1:80 in my browser, which brought me to a GitLab login page. I had forgotten that I had once installed GitLab but wasn't using it. After uninstalling GitLab, port 80 was no longer occupied.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM