![nginx 在全新安装后无法启动](https://linux22.com/image/1013319/nginx%20%E5%9C%A8%E5%85%A8%E6%96%B0%E5%AE%89%E8%A3%85%E5%90%8E%E6%97%A0%E6%B3%95%E5%90%AF%E5%8A%A8.png)
我刚刚从 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
。