我在debian 8.0,8.4或Ubuntu 14.04上有4个不同操作系统版本运行Nginx的单元。从昨天开始NGINX启动失败了我的开发站(它在2天前运行良好)..奇怪!
$ sudo service nginx start
$ Job for nginx.service failed. See 'systemctl status nginx.service' and 'journalctl -xn' for details.
所以寻找日志:
$ sudo systemctl -l status nginx.service
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled)
Active: failed (Result: exit-code) since Thu 2016-04-28 22:15:18 CEST; 6min ago
Process: 24148 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
Process: 24145 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Apr 28 22:15:15 mercure nginx[24148]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 28 22:15:16 mercure nginx[24148]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 28 22:15:16 mercure nginx[24148]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 28 22:15:17 mercure nginx[24148]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 28 22:15:17 mercure nginx[24148]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 28 22:15:18 mercure nginx[24148]: nginx: [emerg] still could not bind()
Apr 28 22:15:18 mercure systemd[1]: nginx.service: control process exited, code=exited status=1
Apr 28 22:15:18 mercure systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Apr 28 22:15:18 mercure systemd[1]: Unit nginx.service entered failed state
和第二期:
$ sudo journalctl -xn
-- Logs begin at Thu 2016-04-28 08:41:36 CEST, end at Thu 2016-04-28 22:23:08 CEST. --
Apr 28 22:22:54 mercure nginx[24290]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 28 22:22:55 mercure nginx[24290]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 28 22:22:55 mercure nginx[24290]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 28 22:22:56 mercure nginx[24290]: nginx: [emerg] still could not bind()
Apr 28 22:22:56 mercure systemd[1]: nginx.service: control process exited, code=exited status=1
Apr 28 22:22:56 mercure systemd[1]: Failed to start A high performance web server and a reverse 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.
Apr 28 22:22:56 mercure systemd[1]: Unit nginx.service entered failed state.
Apr 28 22:22:56 mercure sudo[24263]: pam_unix(sudo:session): session closed for user root
Apr 28 22:23:08 mercure sudo[24293]: jeby6372 : TTY=pts/3 ; PWD=/etc/nginx ; USER=root ; COMMAND=/bin/journalctl -xn
Apr 28 22:23:08 mercure sudo[24293]: pam_unix(sudo:session): session opened for user root by jeby6372(uid=0)
我在/ var / log / syslog中发现了一个奇怪的DHCP行为,不是吗?
Apr 28 22:22:24 mercure NetworkManager[676]: <info> (eth0): DHCPv4 state changed renew -> renew
Apr 28 22:22:24 mercure NetworkManager[676]: <info> address 192.168.1.3
Apr 28 22:22:24 mercure NetworkManager[676]: <info> plen 24 (255.255.255.0)
Apr 28 22:22:24 mercure NetworkManager[676]: <info> gateway 192.168.1.254
Apr 28 22:22:24 mercure NetworkManager[676]: <info> server identifier 192.168.1.1
Apr 28 22:22:24 mercure NetworkManager[676]: <info> lease time 120
Apr 28 22:22:24 mercure NetworkManager[676]: <info> nameserver '192.168.1.1'
Apr 28 22:22:24 mercure NetworkManager[676]: <info> domain name 'hznteam.lan'
Apr 28 22:22:24 mercure NetworkManager[676]: <info> domain search 'hznteam.lan.'
Apr 28 22:22:24 mercure dbus[722]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.service'
Apr 28 22:22:24 mercure dbus[722]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'
Apr 28 22:22:24 mercure nm-dispatcher: Dispatching action 'dhcp4-change' for eth0
Apr 28 22:22:24 mercure dhclient: bound to 192.168.1.3 -- renewal in 47 seconds.
Apr 28 22:22:53 mercure nginx[24290]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 28 22:22:54 mercure nginx[24290]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 28 22:22:54 mercure nginx[24290]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 28 22:22:55 mercure nginx[24290]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 28 22:22:55 mercure nginx[24290]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 28 22:22:56 mercure nginx[24290]: nginx: [emerg] still could not bind()
Apr 28 22:22:56 mercure systemd[1]: nginx.service: control process exited, code=exited status=1
Apr 28 22:22:56 mercure systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Apr 28 22:22:56 mercure systemd[1]: Unit nginx.service entered failed state
runnin Nginx作为前台任务显示0.0.0.0:80已经在使用,但我没有安装apache
jeby6372@mercure:~$ sudo nginx -g "daemon off;"
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()
nmap命令结果表明没有程序正在侦听端口80
jeby6372 @ mercure:〜$ nmap -p 80 localhost
Starting Nmap 6.47 ( http://nmap.org ) at 2016-04-29 18:57 CEST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000054s latency).
Other addresses for localhost (not scanned): 127.0.0.1
PORT STATE SERVICE
80/tcp open http
Nmap done: 1 IP address (1 host up) scanned in 0.04 seconds
有什么想法吗?
答案 0 :(得分:2)
尝试在前台模式下运行nginx以查看失败的原因:
nginx -g "daemon off;"
如果仍然会收到错误:
bind() to 0.0.0.0:80 failed
然后可能已经在端口80上运行了一个服务。 然后尝试使用lsof命令找出它的服务并使用kill -15或kill -9将其终止。您可以通过运行以下命令检查端口80上是否正在运行某些内容:
nmap -p 80 localhost
答案 1 :(得分:1)
看来,其他一些服务正在使用您尝试使用nginx访问的地址或端口。因此,找出使用该端口的任何第二个进程。然后关闭它然后启动nginx。