Nginx failed to start, port 80 is already occupied

#Check Nginx configuration

[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


#Restart Nginx without relying on residual processes

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


#Force kill process

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


#One of the ways to start 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]


#View Nginx service status

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


#View system log

[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 systemd[1]: Started Session 22 of user root.
-- Subject: Unit session-22.scope has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit session-22.scope has finished starting up.
--
-- The start-up result is done.
Jan 02 23:20:01 i-14fe7093 systemd[1]: Starting Session 22 of user root.
-- Subject: Unit session-22.scope has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit session-22.scope has begun starting up.
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 18:38:04 localhost.localdomain kernel: pci_bus 0000:00: resource 4 [io  0x0000-0x0cf7]
Jan 02 18:38:04 localhost.localdomain kernel: pci_bus 0000:00: resource 5 [io  0x0d00-0xffff]
Jan 02 18:38:04 localhost.localdomain kernel: pci_bus 0000:00: resource 6 [mem 0x000a0000-0x000bffff]
Jan 02 18:38:04 localhost.localdomain kernel: pci_bus 0000:00: resource 7 [mem 0xc0000000-0xfebfffff]
Jan 02 18:38:04 localhost.localdomain kernel: NET: Registered protocol family 2
Jan 02 18:38:04 localhost.localdomain kernel: TCP established hash table entries: 65536 (order: 7, 524288 bytes)
Jan 02 18:38:04 localhost.localdomain kernel: TCP bind hash table entries: 65536 (order: 8, 1048576 bytes)
Jan 02 18:38:04 localhost.localdomain kernel: TCP: Hash tables configured (established 65536 bind 65536)
Jan 02 18:38:04 localhost.localdomain kernel: TCP: reno registered
Jan 02 18:38:04 localhost.localdomain kernel: UDP hash table entries: 4096 (order: 5, 131072 bytes)
Jan 02 18:38:04 localhost.localdomain kernel: UDP-Lite hash table entries: 4096 (order: 5, 131072 bytes)
Jan 02 18:38:04 localhost.localdomain kernel: NET: Registered protocol family 1
Jan 02 18:38:04 localhost.localdomain kernel: pci 0000:00:00.0: Limiting direct PCI/PCI transfers
Jan 02 18:38:04 localhost.localdomain kernel: pci 0000:00:01.0: PIIX3: Enabling Passive Release
Jan 02 18:38:04 localhost.localdomain kernel: pci 0000:00:01.0: Activating ISA DMA hang workarounds
Jan 02 18:38:04 localhost.localdomain kernel: pci 0000:00:02.0: Boot video device
Jan 02 18:38:04 localhost.localdomain kernel: ACPI: PCI Interrupt Link [LNKD] enabled at IRQ 11
Jan 02 18:38:04 localhost.localdomain kernel: ACPI: PCI Interrupt Link [LNKA] enabled at IRQ 10
Jan 02 18:38:04 localhost.localdomain kernel: ACPI: PCI Interrupt Link [LNKB] enabled at IRQ 10
Jan 02 18:38:04 localhost.localdomain kernel: ACPI: PCI Interrupt Link [LNKC] enabled at IRQ 11
Jan 02 18:38:04 localhost.localdomain kernel: PCI: CLS 0 bytes, default 64
Jan 02 18:38:04 localhost.localdomain kernel: Unpacking initramfs...
Jan 02 18:38:04 localhost.localdomain kernel: Freeing initrd memory: 17284k freed
Jan 02 18:38:04 localhost.localdomain kernel: PCI-DMA: Using software bounce buffering for IO (SWIOTLB)
Jan 02 18:38:04 localhost.localdomain kernel: software IO TLB [mem 0xbbffe000-0xbfffe000] (64MB) mapped at [ffff8800bbffe000-ffff8800bfffdfff]
Jan 02 18:38:04 localhost.localdomain kernel: microcode: CPU0 sig=0x206a1, pf=0x1, revision=0x1
Jan 02 18:38:04 localhost.localdomain kernel: microcode: CPU1 sig=0x206a1, pf=0x1, revision=0x1
Jan 02 18:38:04 localhost.localdomain kernel: microcode: CPU2 sig=0x206a1, pf=0x1, revision=0x1
Jan 02 18:38:04 localhost.localdomain kernel: microcode: CPU3 sig=0x206a1, pf=0x1, revision=0x1
Jan 02 18:38:04 localhost.localdomain kernel: microcode: Microcode Update Driver: v2.00 <[email protected]>, Peter Oruba
Jan 02 18:38:04 localhost.localdomain kernel: sha1_ssse3: Using AVX2 optimized SHA-1 implementation
Jan 02 18:38:04 localhost.localdomain kernel: sha256_ssse3: Using AVX2 optimized SHA-256 implementation
Jan 02 18:38:04 localhost.localdomain kernel: futex hash table entries: 1024 (order: 4, 65536 bytes)
Jan 02 18:38:04 localhost.localdomain kernel: Initialise system trusted keyring
Jan 02 18:38:04 localhost.localdomain kernel: audit: initializing netlink socket (disabled)
Jan 02 18:38:04 localhost.localdomain kernel: type=2000 audit(1514889484.625:1): initialized
Jan 02 18:38:04 localhost.localdomain kernel: HugeTLB registered 1 GB page size, pre-allocated 0 pages
Jan 02 18:38:04 localhost.localdomain kernel: HugeTLB registered 2 MB page size, pre-allocated 0 pages
Jan 02 18:38:04 localhost.localdomain kernel: zpool: loaded
Jan 02 18:38:04 localhost.localdomain kernel: zbud: loaded
Jan 02 18:38:04 localhost.localdomain kernel: VFS: Disk quotas dquot_6.5.2
Jan 02 18:38:04 localhost.localdomain kernel: Dquot-cache hash table entries: 512 (order 0, 4096 bytes)
/bin/bash: -c: line 0: syntax error near unexpected token `('
/bin/bash: -c: line 0: `lessecho -p0x22 -d0x22 -e\\ -n0x3b -n0x20 -n0x2a -n0x3f -n0x9 -n0xa -n0x27 -n0x22 -n0x28 -n0x29 -n0x3c -n0x3e -n0x5b -n0x5d -n0x7c -n0x26 -n0x5e -n0x60 -n0x23 -n0x5c -n0x24 -n0x25 -n0x3d -n0x7e -- ervice failed. Failed to start SYSV: Nginx is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server.'
...skipping...
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 systemd[1]: Started Session 22 of user root.
-- Subject: Unit session-22.scope has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit session-22.scope has finished starting up.
--
-- The start-up result is done.
Jan 02 23:20:01 i-14fe7093 systemd[1]: Starting Session 22 of user root.
-- Subject: Unit session-22.scope has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit session-22.scope has begun starting up.
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 lists the listening TCP ports, -u or --udp displays the connection status of the UDP transport protocol, -n does not resolve the host, port, name in the output, -p displays the process ID and name

[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


#kill the process with the specified PID

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


#Check if the process is killed

[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


#Restart Nginx, no residual process occupies port 80 at this time

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325172595&siteId=291194637