./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