启动nginx 80端口被占用:tcp 0 0 127.0.0.1:80 127.0.0.1:34932 TIME_WAIT

1.启动nginx命令
./sbin/nginx

2.提示80端口被占用

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()

3.执行netstat -antp查看谁占用了80端口

Proto  Recv-Q  Send-Q  Local Address           Foreign Address         State               PID/Program name   

tcp        0           0           127.0.0.1:80               127.0.0.1:34932         TIME_WAIT      -   

4.通过调整内核参数解决

vi /etc/sysctl.conf


编辑文件,加入以下内容:
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 30
 
然后执行/sbin/sysctl -p让参数生效。
5.关闭窗口断开连接,重新打开

80端口仍被占用

Proto   Recv-Q   Send-Q         Local Address   Foreign Address     State             PID/Program name
tcp              0          0                0.0.0.0:80           0.0.0.0:*              LISTEN           1402/nginx: master

6.kill占用80端口的进程

7./sbin/nginx

此时,启动nginx成功

执行命令 kill -9 1402
参考资料:https://blog.csdn.net/gzh0222/article/details/8491178

原文地址:https://www.cnblogs.com/songsongblue/p/11788649.html