nginx 在全新安装后无法启动

nginx 在全新安装后无法启动

我刚刚从 digitalocean 购买了一个新的 droplet,并且安装了 nginx 并sudo apt install nginx 尝试查看它是否运行,但它出现了以下错误:

root@school:~# systemctl status nginx.service
● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2019-05-20 19:27:11 UTC; 22s ago
     Docs: man:nginx(8)
  Process: 21174 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
  Process: 21160 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
 Main PID: 851 (code=exited, status=0/SUCCESS)

May 20 19:27:10 school nginx[21174]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
May 20 19:27:10 school nginx[21174]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
May 20 19:27:10 school nginx[21174]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
May 20 19:27:10 school nginx[21174]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
May 20 19:27:11 school nginx[21174]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
May 20 19:27:11 school nginx[21174]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
May 20 19:27:11 school nginx[21174]: nginx: [emerg] still could not bind()
May 20 19:27:11 school systemd[1]: nginx.service: Control process exited, code=exited status=1
May 20 19:27:11 school systemd[1]: nginx.service: Failed with result 'exit-code'.
May 20 19:27:11 school systemd[1]: Failed to start A high performance web server and a reverse proxy server.

这是我的防火墙设置:

To                         Action      From
--                         ------      ----
80/tcp                     ALLOW       Anywhere                  
22                         ALLOW       Anywhere                  
3306                       ALLOW       Anywhere                  
Apache                     ALLOW       Anywhere                  
Nginx HTTP                 ALLOW       Anywhere                  
Nginx HTTPS                ALLOW       Anywhere                  
80/tcp (v6)                ALLOW       Anywhere (v6)             
22 (v6)                    ALLOW       Anywhere (v6)             
3306 (v6)                  ALLOW       Anywhere (v6)             
Apache (v6)                ALLOW       Anywhere (v6)             
Nginx HTTP (v6)            ALLOW       Anywhere (v6)             
Nginx HTTPS (v6)           ALLOW       Anywhere (v6)

你们中有人清楚问题是什么吗?谢谢您的宝贵时间

sudo netstat -tlpn | grep :80

得到以下结果:

root@school:~# sudo netstat -tlpn | grep :80
tcp6       0      0 :::80                   :::*                    LISTEN      16792/apache2 

答案1

结果sudo netstat -tlpn | grep :80表明你正在运行 Apache。两个进程不能同时监听同一个套接字,所以这就是 nginx 无法启动的原因。

您可以使用 停止 Apache sudo systemctl stop apache2,如果需要,也可以使用 禁用它sudo systemctl disable apache2。后一个命令将永久禁用 Apache 的自动启动。

如果要删除 Apache,请运行sudo apt remove apache2 apache2-data apache2-utils

相关内容