我知道这类似的问题,但我似乎无法通过阅读它解决我的问题。
背景
我正在努力奔跑计时表通过 Nginx。我已经运行了一些 Nginx 块。
对于这一点,我遵循以下示例这里,因此我在这个位置设置了以下文件/etc/nginx/sites-available/chronograf.baseurl.com
::
server {
server_name chronograf.baseurl.com www.chronograf.baseurl.com;
location / {
proxy_pass http://localhost:8888/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
然后我检查语法sudo nginx -t
并发现一切正常:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
最后我运行sudo systemctl restart nginx
并失败了:
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.
帖子/var/log/nginx/error.log
:
2020/05/27 02:22:27 [info] 4740#4740: Using 32768KiB of shared memory for nchan in /etc/nginx/nginx.conf:63
2020/05/27 02:22:27 [emerg] 4751#4751: bind() to 0.0.0.0:80 failed (98: Address already in use)
2020/05/27 02:22:27 [emerg] 4751#4751: bind() to 0.0.0.0:443 failed (98: Address already in use)
2020/05/27 02:22:27 [emerg] 4751#4751: bind() to 0.0.0.0:80 failed (98: Address already in use)
2020/05/27 02:22:27 [emerg] 4751#4751: bind() to 0.0.0.0:443 failed (98: Address already in use)
2020/05/27 02:22:27 [emerg] 4751#4751: bind() to 0.0.0.0:80 failed (98: Address already in use)
2020/05/27 02:22:27 [emerg] 4751#4751: bind() to 0.0.0.0:443 failed (98: Address already in use)
2020/05/27 02:22:27 [emerg] 4751#4751: bind() to 0.0.0.0:80 failed (98: Address already in use)
2020/05/27 02:22:27 [emerg] 4751#4751: bind() to 0.0.0.0:443 failed (98: Address already in use)
2020/05/27 02:22:27 [emerg] 4751#4751: bind() to 0.0.0.0:80 failed (98: Address already in use)
2020/05/27 02:22:27 [emerg] 4751#4751: bind() to 0.0.0.0:443 failed (98: Address already in use)
2020/05/27 02:22:27 [emerg] 4751#4751: still could not bind()
有人可以帮我调试这个吗?
更新 1
根据@Pandurang 的建议:
- 我停下
nginx
来跑步sudo systemctl stop nginx
。 - 然后我运行
ps -ef | grep nginx
命令。
它返回以下输出:
root 846 821 0 Apr13 ? 00:45:11 runsv nginx
root 870 846 0 Apr13 ? 00:47:39 svlogd -tt /var/log/gitlab/nginx
stelian 3028 2943 0 15:47 pts/0 00:00:00 grep --color=auto nginx
root 32462 846 0 01:47 ? 00:00:00 nginx: master process /opt/gitlab/embedded/sbin/nginx -p /var/opt/gitlab/nginx
gitlab-+ 32493 32462 0 01:47 ? 00:00:00 nginx: worker process
gitlab-+ 32494 32462 0 01:47 ? 00:00:00 nginx: worker process
gitlab-+ 32495 32462 0 01:47 ? 00:00:00 nginx: worker process
gitlab-+ 32496 32462 0 01:47 ? 00:01:18 nginx: worker process
gitlab-+ 32497 32462 0 01:47 ? 00:00:00 nginx: cache manager process
我怀疑 nginx 和 GitLab 之间存在冲突?
答案1
2020/05/27 02:22:27 [emerg] 4751#4751: bind() to 0.0.0.0:80 failed (98: Address already in use)
2020/05/27 02:22:27 [emerg] 4751#4751: bind() to 0.0.0.0:443 failed (98: Address already in use)
问题是端口 80 和 443 已在某些地方被使用:Address already in use
调试的下一步是使用netstat
和来确定哪个进程正在监听(或“绑定到”)相关端口egrep
:
sudo netstat -nap | egrep ':(80|443)\s.*LISTEN'
(需要 root 权限netstat -p
,打印相关进程信息)
以下是 nginx 正在监听的一个例子:
$ sudo netstat -nap | egrep ':(80|443)\s.*LISTEN'
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 4498/nginx: worker
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 4498/nginx: worker
tcp6 0 0 :::80 :::* LISTEN 4498/nginx: worker
tcp6 0 0 :::443 :::* LISTEN 4498/nginx: worker
$
答案2
使用netstat -an | grep :80
命令检查该端口是否被其他服务使用。
答案3
我最近遇到了这个错误,对我来说,解决方案是 apache 也同时运行。您可以通过以下方式检查
sudo systemctl status apache2
如果它正在运行,此命令将停止它
sudo systemctl stop apache2
这将阻止 apache 运行
sudo systemctl disable apache2