Nginx启动失败,80端口已被占用

#检查Nginx配置

[root@i-14fe7093 nginx]# ./sbin/nginx -t -c ./conf/nginx.conf

nginx: the configuration file /usr/local/nginx/./conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/./conf/nginx.conf test is successful


#不依靠残留进程,重新启动Nginx

[root@i-14fe7093 nginx]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
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()


#强制性杀死进程

[root@i-14fe7093 nginx]# pkill -9 nginx
[root@i-14fe7093 nginx]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
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()


#启动Nginx方式之一

[root@i-14fe7093 nginx]# /etc/init.d/nginx start
Starting nginx (via systemctl):  Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.  [FAILED]


#查看Nginx服务状态

[root@i-14fe7093 nginx]# systemctl status nginx.service
â— nginx.service - SYSV: Nginx is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server
   Loaded: loaded (/etc/rc.d/init.d/nginx)
   Active: failed (Result: exit-code) since Tue 2018-01-02 23:19:52 CST; 38s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 15553 ExecStart=/etc/rc.d/init.d/nginx start (code=exited, status=1/FAILURE)

Jan 02 23:19:50 i-14fe7093 nginx[15553]: nginx: [emerg] bind() to 0.0.0.0:80...)
Jan 02 23:19:51 i-14fe7093 nginx[15553]: nginx: [emerg] bind() to 0.0.0.0:80...)
Jan 02 23:19:51 i-14fe7093 nginx[15553]: nginx: [emerg] bind() to 0.0.0.0:80...)
Jan 02 23:19:52 i-14fe7093 nginx[15553]: nginx: [emerg] bind() to 0.0.0.0:80...)
Jan 02 23:19:52 i-14fe7093 nginx[15553]: nginx: [emerg] still could not bind()
Jan 02 23:19:52 i-14fe7093 nginx[15553]: [FAILED]
Jan 02 23:19:52 i-14fe7093 systemd[1]: nginx.service: control process exite...=1
Jan 02 23:19:52 i-14fe7093 systemd[1]: Failed to start SYSV: Nginx is an HT...r.
Jan 02 23:19:52 i-14fe7093 systemd[1]: Unit nginx.service entered failed state.
Jan 02 23:19:52 i-14fe7093 systemd[1]: nginx.service failed.

Hint: Some lines were ellipsized, use -l to show in full.


#查看系统日志

[root@i-14fe7093 nginx]# journalctl -xe
Jan 02 23:19:49 i-14fe7093 systemd[1]: Starting SYSV: Nginx is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server...
-- Subject: Unit nginx.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit nginx.service has begun starting up.
Jan 02 23:19:50 i-14fe7093 nginx[15553]: Starting nginx: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jan 02 23:19:50 i-14fe7093 nginx[15553]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jan 02 23:19:51 i-14fe7093 nginx[15553]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jan 02 23:19:51 i-14fe7093 nginx[15553]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jan 02 23:19:52 i-14fe7093 nginx[15553]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jan 02 23:19:52 i-14fe7093 nginx[15553]: nginx: [emerg] still could not bind()
Jan 02 23:19:52 i-14fe7093 nginx[15553]: [FAILED]
Jan 02 23:19:52 i-14fe7093 systemd[1]: nginx.service: control process exited, code=exited status=1
Jan 02 23:19:52 i-14fe7093 systemd[1]: Failed to start SYSV: Nginx is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server.
-- Subject: Unit nginx.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit nginx.service has failed.
--
-- The result is failed.
Jan 02 23:19:52 i-14fe7093 systemd[1]: Unit nginx.service entered failed state.
Jan 02 23:19:52 i-14fe7093 systemd[1]: nginx.service failed.
Jan 02 23:19:52 i-14fe7093 polkitd[1300]: Unregistered Authentication Agent for unix-process:15548:1690636 (system bus name :1.71, object path /org/freedesktop/PolicyKi
Jan 02 23:19:52 i-14fe7093 root[15630]: [euid=root]:root pts/0 2018-01-02 23:07 (10.247.123.130):[/usr/local/nginx]2018-01-02 23:19:49 root /etc/init.d/nginx start
Jan 02 23:20:01 i-14fe7093 CROND[15632]: (root) CMD (/sbin/ntpdate pool.ntp.org > /dev/null 2>&1)
Jan 02 23:20:31 i-14fe7093 root[15675]: [euid=root]:root pts/0 2018-01-02 23:07 (10.247.123.130):[/usr/local/nginx]2018-01-02 23:20:31 root systemctl status nginx.servi
Jan 02 23:20:58 i-14fe7093 root[15685]: [euid=root]:root pts/0 2018-01-02 23:07 (10.247.123.130):[/usr/local/nginx]2018-01-02 23:20:31 root systemctl status nginx.servi
-- Logs begin at Tue 2018-01-02 18:38:04 CST, end at Tue 2018-01-02 23:20:58 CST. --
Jan 02 23:19:49 i-14fe7093 systemd[1]: Starting SYSV: Nginx is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server...
-- Subject: Unit nginx.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit nginx.service has begun starting up.
Jan 02 23:19:50 i-14fe7093 nginx[15553]: Starting nginx: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jan 02 23:19:50 i-14fe7093 nginx[15553]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jan 02 23:19:51 i-14fe7093 nginx[15553]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jan 02 23:19:51 i-14fe7093 nginx[15553]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jan 02 23:19:52 i-14fe7093 nginx[15553]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jan 02 23:19:52 i-14fe7093 nginx[15553]: nginx: [emerg] still could not bind()
Jan 02 23:19:52 i-14fe7093 nginx[15553]: [FAILED]
Jan 02 23:19:52 i-14fe7093 systemd[1]: nginx.service: control process exited, code=exited status=1
Jan 02 23:19:52 i-14fe7093 systemd[1]: Failed to start SYSV: Nginx is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server.
-- Subject: Unit nginx.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit nginx.service has failed.
--
-- The result is failed.
Jan 02 23:20:01 i-14fe7093 CROND[15632]: (root) CMD (/sbin/ntpdate pool.ntp.org > /dev/null 2>&1)
Jan 02 23:20:31 i-14fe7093 root[15675]: [euid=root]:root pts/0 2018-01-02 23:07 (10.247.123.130):[/usr/local/nginx]2018-01-02 23:20:31 root systemctl status nginx.servi
Jan 02 23:20:58 i-14fe7093 root[15685]: [euid=root]:root pts/0 2018-01-02 23:07 (10.247.123.130):[/usr/local/nginx]2018-01-02 23:20:31 root systemctl status nginx.servi


# -lt  列出监听的TCP端口, -u 或 --udp 显示UDP传输协议的连线状况,-n 输出中不解析主机、端口、名称, -p 显示进程ID和名称

[root@i-14fe7093 nginx]# netstat -ltunp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:11211         0.0.0.0:*               LISTEN      1065/memcached
tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      1005/redis-server 1
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      816/sshd
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      958/master
tcp        0      0 10.247.110.35:95        0.0.0.0:*               LISTEN      891/python
tcp6       0      0 :::8080                 :::*                    LISTEN      1160/java
tcp6       0      0 :::80                   :::*                    LISTEN      812/httpd
tcp6       0      0 :::22                   :::*                    LISTEN      816/sshd
tcp6       0      0 ::1:25                  :::*                    LISTEN      958/master
tcp6       0      0 :::443                  :::*                    LISTEN      812/httpd
tcp6       0      0 127.0.0.1:8006          :::*                    LISTEN      1160/java
udp        0      0 127.0.0.1:11211         0.0.0.0:*                           1065/memcached
udp        0      0 0.0.0.0:68              0.0.0.0:*                           756/dhclient
udp        0      0 0.0.0.0:28965           0.0.0.0:*                           756/dhclient

udp6       0      0 :::50624                :::*                                756/dhclient


#杀死指定PID的进程

[root@i-14fe7093 nginx]# kill 812


#检验进程是否杀死

[root@i-14fe7093 nginx]# netstat -ltunp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:11211         0.0.0.0:*               LISTEN      1065/memcached
tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      1005/redis-server 1
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      816/sshd
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      958/master
tcp        0      0 10.247.110.35:95        0.0.0.0:*               LISTEN      891/python
tcp6       0      0 :::8080                 :::*                    LISTEN      1160/java
tcp6       0      0 :::22                   :::*                    LISTEN      816/sshd
tcp6       0      0 ::1:25                  :::*                    LISTEN      958/master
tcp6       0      0 127.0.0.1:8006          :::*                    LISTEN      1160/java
udp        0      0 127.0.0.1:11211         0.0.0.0:*                           1065/memcached
udp        0      0 0.0.0.0:68              0.0.0.0:*                           756/dhclient
udp        0      0 0.0.0.0:28965           0.0.0.0:*                           756/dhclient

udp6       0      0 :::50624                :::*                                756/dhclient


#重启Nginx,此时没有残留进程占用80端口了

[root@i-14fe7093 nginx]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值