网站打开都是502,服务器环境是centos+lnmp的环境,先去看看nginx的状态service nginx
status,果然看到nginx服务挂了,执行service nginx start启动nginx服务,无法开启,提示错误如下:
Starting nginx: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] still could not bind()
大概意思就是:端口地址已被使用,但是我们没有其他使用80端口的服务了,很大的可能nginx服务进程卡死了,导致80端口被占用。
解决办法
首先用lsof -i :80查看80端口被什么程序占用,返回结果如下,
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME nginx 3274 root 6u IPv4 10664 0t0 TCP :http (LISTEN) nginx 3547 nginx 6u IPv4 10664 0t0 TCP :http (LISTEN) .....
发现是nginx进程占用了80端口,所以我们把nginx进程kill掉,重新启动服务。
命令如下(kill 掉所有的nginx进程):
kill -9 lsof -i :80 |grep nginx |grep -v grep|awk '{print $2}' service nginx start Starting nginx... [ OK ]
OK,nginx服务已经成功启动!