英文:
Can't start nginx in WSL
问题
我曾在Windows和WSL上使用开发环境,直接在我的WSL机器上安装了docker和nginx来处理反向代理,但现在当我尝试启动nginx时,出现错误"98: 未知错误",并且使用命令"sudo nginx -t"时,它显示"bind()到0.0.0.0:80失败"和"0.0.0.0:443失败",我该怎么做来修复这个问题?
英文:
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?
答案1
得分: 1
问题
Ubuntu WSL 预装了 Apache Web 服务器,它使用默认的 Web 端口(80),因此当您尝试使用默认设置启动 Nginx(也在端口80上)时,会出现绑定错误。
当然,已经有多个原因导致端口80已经被使用,您需要检查正在使用它的应用程序是什么。
如何检查
选项1:
- 打开 Ubuntu(Linux)终端
- 输入
sudo systemctl status apache2
- 如果看到一些告诉您它正在运行的消息,那么它确实使用端口80,否则是其他原因。
选项2:
- 打开浏览器,在地址栏中键入
localhost
- 如果显示默认的 Apache 安装页面,那么它确实是罪魁祸首
解决方案
此解决方案是针对 Apache2 是罪魁祸首的情况,对于可能使用端口80的任何其他应用程序,您需要自行找到如何禁用它的方法
- 使用
sudo systemctl stop apache2
停止它 - 您还需要禁用它,以便下次重新启动计算机时不会自动启动,键入
sudo systemctl disable apache2
- 完成后,您可以尝试重新启动 Nginx:
sudo systemctl start nginx
- 并使其自动启动:
sudo systemctl enable nginx
当然,您也可以像这里一样更改 Nginx 使用的端口 在 Nginx 上使用其他端口
如果您决定更改 Nginx 端口,请注意,任何侦听由其他应用程序使用的端口的主机都会导致 Nginx 无法启动,因此如果在 Nginx 配置中有多个主机,则还需要更新它们。
英文:
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:
- open the ubuntu (linux) terminal
- type
sudo systemctl status apache2
- if you see some message that tells its running, then it does using port 80, if not, then its something else
option 2:
- open a browser and type
localhost
in the address bar - if its showing default apache install page, then its truly the culprit
solution
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
- stop it using
sudo systemctl stop apache2
- you need to disable it too, so that next time you restart your pc, it wont auto-start, type
sudo systemctl disable apache2
- after this, you can try starting the nginx again:
sudo systemctl start nginx
- and make it auto-start:
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
答案2
得分: 0
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.
sudo service nginx restart
There are other stuffs too that are confusing but at least I can see my nginx in action and working.
英文:
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.
sudo service nginx restart
There are other stuffs too that are confusing but atleast I can see my nginx in action and working.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论