Score:0

nginx address already in use, no matter what port configured

sm flag

I am trying to use nginx to host a webpage. Running on a local VM immediately works, but on an external server not.

When typing nginx into the console, the error reads as follows:

nginx: [emerg] bind() to 0.0.0.0:8080 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:8080 failed (98: Address already in use)
...

Running netstat to see what ports are used gave this output:

root@vm-1234567-41:~# netstat -lnp | grep -E ':80|8080'
tcp    0    0 0.0.0.0:8080    0.0.0.0:*    LISTEN    894/nginx: master p

To me, this looks like it should. Only nginx is using the port so there shouldn't be another program using it, right?

Some things that didn't solve the issue:

  • sudo killall nginx and then sudo systemctl start nginx
  • stopping nginx with systemctl stop nginx and restarting again
  • changing the port to any other port (always resulted in the same "Address already in use" error message)

Not sure if these actually have an influence, but I tried it anyways (without success):

  • allowing http and https traffic with ufw
  • allowing ports (80, 8080, etc.) with ufw

How would I go about fixing this? I'm at the point of thinking that the error message itself is hinting at a wrong error.

P.S:

  • running apache2 in the console is not recognized
  • running httpd in the console is not recognized
  • a Squid caching server is installed, but I'm not sure how to go about checking whether that is causing the issue.
us flag
What are you trying to achieve by running `nginx` in the console?
Score:2
ws flag

Stop running things in the console. There is a use-case for this and there are specific options in both nginx and Apache to handle this use-case which you are not using - it appears you are just trying stuff at random.

error reads as...Address already in use

Yes, nginx is already running you can't start another daemon listing on the port even if its exactly the same binary.

You need to stop the running daemon to start your nginx. Given the things you've tried already I would not be surprised if there is more than instance of nginx installed on the host, or more than startup mechanism. Reboot your host and run systemctl status nginx.

When you change your nginx config, test it with nginx -t. If there are no errors reported, apply it with systemctl reload nginx. If, for some reason, you want to take the nginx server offline but leave the host running, run systemctl stop nginx. You can start it again with systemctl start nginx.

Thomas3k24 avatar
sm flag
I feel stupid for not realizing that executing `nginx` in the console was the reason why another process was started- I thought it would check the current nginx status. It may seem quite random since I'm trying to search the internet for similar issues and trying their solutions. Thanks for your suggestions!
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.