啟動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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM