I was using a dev environment with Windows and WSL with docker and nginx installed directly in my WSL machine to handle the proxy reverse, but now when I’m trying to start nginx, I’m getting the error "98: Unknown error" and using the command "sudo nginx -t", it shows me "bind() to 0.0.0.0:80 failed" and "0.0.0.0:443 failed", what can I do to fix this?
2
Answers
problem
ubuntu wsl comes with apache web server pre-installed, its using the default web port (80), so when you try to start nginx with default setting (also on port 80) it will have bind error
but of-course, there are multiple reason that port 80 is already used, in which you need to check what app that is using it
how to check
option 1:
sudo systemctl status apache2
option 2:
localhost
in the address barsolution
this solution is for when apache2 is the culprit, for any other app that might use port 80, you need to find how to disable it yourself
sudo systemctl stop apache2
sudo systemctl disable apache2
sudo systemctl start nginx
sudo systemctl enable nginx
of-course, you can just change the port used by nginx like here use other port on nginx
if you decide to change nginx port, please note that any host listening on port that is used by other app will make nginx fail to start, so if you have more than 1 host on nginx config, you need to update them too
I was playing around local nginx proxy with nodejs API listening at port :5000. Had same and other permission errors, finally I realized that port 80 is already being used by my local IIS.
Stopped IIS to free port :80 and restarted nginx service.
There are other stuffs too that are confusing but atleast I can see my nginx in action and working.