nginx 错误使用总结

一、sudo nginx 后出现下面的报错:

nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use)
nginx: [emerg] still could not bind()

执行 sudo nginx 之前,我执行 nginx。我原以为 nginx 这条命令是无法启动 ngixn的,所以再执行 sudo nginx 的时候,就出现了上面的报错。

我一直都没有意识到 ,nginx 这条命令已经将 nginx 开启了,只不过可能与 sudo nginx 有些不一样。

结果,我还花了十几分去 google 进行搜索。

然后,通过命令 ps ax -o pid,ppid,%cpu,vsz,wchan,command|egrep '(nginx|PID)' 查看到居然有 nginx 在跑。

PID PPID %CPU VSZ WCHAN COMMAND
975 1 0.0 2455800 - nginx: master process nginx
976 975 0.0 2456028 - nginx: worker process
1553 861 0.0 2452248 - egrep (nginx|PID)

然后,我直接执行 sudo nginx -s stop 将 nginx 服务停掉,再 sudo nginx 就OK。

其他的命令:
lsof -i:80
sudo find / -name nginx.pid

你可能感兴趣的:(nginx 错误使用总结)