./nginx启动nginx,启动时,错误端口被占用
[root@localhost sbin]# ./nginx nginx: [emerg] bind() to 0.0.0.0:7001 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:7001 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:7001 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:7001 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:7001 failed (98: Address already in use)
lsof -i:7001,检查被占用的过程
[root@localhost sbin]# lsof -i:7001 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME java 104324 root 1514u IPv6 822256 0t0 TCP localhost.localdomain:afs3-callback (LISTEN) java 104324 root 1515u IPv6 811847 0t0 TCP localhost:afs3-callback (LISTEN) java 104324 root 1516u IPv6 810961 0t0 TCP localhost:afs3-callback (LISTEN) java 104324 root 1517u IPv6 810962 0t0 TCP localhost.localdomain:afs3-callback (LISTEN) java 104324 root 1518u IPv6 822257 0t0 TCP localhost.localdomain:afs3-callback (LISTEN)
解决办法:
方法一:如果不需要所涉及的过程,杀死它,杀死它./nginx重新启动nginx,80端口同理
[root@localhost nginx]# kill -9 7001 [root@localhost sbin]# ./nginx
方法二:如果涉及到过程需要,则修改端口
进入sbin目录下修改nginx.conf文件
修改前:
server { listen 7001; server_name localhost;
修改后:
将listen将端口改为其他端口
server { listen 17001; server_name localhost;
./nginx 重新启动nginx
[root@localhost sbin]# ./nginx
ps -ef | grep nginx查看过程:已启动
[root@localhost sbin]# ps -ef | grep nginx root 106562 1 0 23:19 ? 00:00:00 nginx: master process ./nginx nobody 106563 106562 0 23:19 ? 00:00:00 nginx: worker process nobody 106564 106562 0 23:19 ? 00:00:00 nginx: worker process root 106568 106205 0 23:19 pts/0 00:00:00 grep --color=auto nginx