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

Nginx启动失败可能有多种原因,以下是常见的几种情况: 1. **配置文件错误**:Nginx依赖于其主配置文件(通常为`nginx.conf`),如果语法错误或配置项设置不当,可能导致启动失败。检查配置文件是否存在、权限正确以及内容是否符合规范。 2. **依赖缺失**:Nginx运行需要一些系统库和依赖,如pcre、openssl等,如果安装不全或版本不兼容,可能无法启动。确认所有必要的库已安装并正确配置。 3. **日志目录权限问题**:Nginx会尝试写入日志到指定路径,如果没有足够的权限,它将无法创建或写入日志,这时可能会显示相关的错误消息。 4. **进程限制**:某些系统设置了最大进程数,当试图超过这个限制启动新进程时,Nginx会因为资源不足而失败。 5. **端口冲突**:如果你尝试绑定的端口已被其他服务占用Nginx也无法启动。可以查看系统中是否有其他服务监听相同的端口。 6. **环境变量**:有些情况下,环境变量设置不正确,比如PATH或LD_LIBRARY_PATH未包含Nginx的bin目录。 7. **软件包问题**:如果是通过包管理器安装的Nginx,可能是由于软件包更新或损坏导致的问题,需要重新安装或更新。 8. **硬件问题**:极少数情况下,可能是硬件资源不足或者网络连接问题影响了Nginx启动。 解决这类问题时,通常先查看Nginx的日志(通常是`/var/log/nginx/error.log`),这能提供详细的错误信息帮助定位问题。根据错误提示逐一排查上述可能性即可。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值