Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details. invoke-rc.d: initscript nginx, action "start" failed. dpkg: error processing package nginx-core (--configure): subprocess installed post-installation script returned error exit status 1 dpkg: dependency problems prevent configuration of nginx: nginx depends on nginx-core (>= 1.10.3-0ubuntu0.16.04.2) | nginx-full (>= 1.10.3-0ubuntu0.16.04.2) | nginx-light (>= 1.10.3-0ubuntu0.16.04.2) | nginx-extras (>= 1.10.3-0ubuntu0.16.04.2); however: Package nginx-core is not configured yet. Package nginx-full is not installed. Package nginx-light is not installed. Package nginx-extras is not installed. nginx depends on nginx-core (<< 1.10.3-0ubuntu0.16.04.2.1~) | nginx-full (<< 1.10.3-0ubuntu0.16.04.2.1~) | nginx-light (<< 1.10.3-0ubuntu0.16.04.2.1~) | nginx-extras (<< 1.10.3-0ubuntu0.16.04.2.1~); however: Package nginx-core is not configured yet. No apport report written because the error message indicates its a followup error from a previous failure. Package nginx-full is not installed. Package nginx-light is not installed. Package nginx-extras is not installed.
dpkg: error processing package nginx (--configure): dependency problems - leaving unconfigured Processing triggers for libc-bin (2.23-0ubuntu9) ... Errors were encountered while processing: nginx-core nginx E: Sub-process /usr/bin/dpkg returned an error code (1)
查看nginx.service状态
1
$ systemctl status nginx.service
1 2 3 4 5 6 7 8 9 10 11 12
● nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Sat 2018-03-17 23:16:40 CST; 1min 18s ago Process: 26795 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE) Main PID: 18259 (code=exited, status=0/SUCCESS)
Mar 17 23:16:40 VM-0-5-ubuntu systemd[1]: Starting A high performance web server and a reverse proxy server... Mar 17 23:16:40 VM-0-5-ubuntu nginx[26795]: nginx: [emerg] open() "/etc/nginx/nginx.conf" failed (2: No such file or direMar 17 23:16:40 VM-0-5-ubuntu nginx[26795]: nginx: configuration file /etc/nginx/nginx.conf test failed Mar 17 23:16:40 VM-0-5-ubuntu systemd[1]: nginx.service: Control process exited, code=exited status=1 Mar 17 23:16:40 VM-0-5-ubuntu systemd[1]: Failed to start A high performance web server and a reverse proxy server. Mar 17 23:16:40 VM-0-5-ubuntu systemd[1]: nginx.service: Unit entered failed state. Mar 17 23:16:40 VM-0-5-ubuntu systemd[1]: nginx.service: Failed with result 'exit-code'.
仔细看报错信息,获取到两个信息点:
Package nginx-core is not configured yet.
Package nginx-full/nginx-light/nginx-extras is not installed.
于是上网搜,网上找说可能是apache占用了80端口导致报错
查看端口占用情况
1
$ sudo netstat -nlp
1 2 3 4 5 6 7 8
Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1287/sshd udp 0 0 0.0.0.0:68 0.0.0.0:* 891/dhclient udp 0 0 172.21.0.5:123 0.0.0.0:* 1231/ntpd udp 0 0 127.0.0.1:123 0.0.0.0:* 1231/ntpd udp 0 0 0.0.0.0:123 0.0.0.0:* 1231/ntpd udp6 0 0 :::123 :::* 1231/ntpd
发现 80 端口没被占用,而且systemctl status nginx.service的提示信息也没提及 80 端口被占用,如果提示信息中说 80 端口被占用,可以执行以下两步试试:
Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: fontconfig-config fonts-dejavu-core libfontconfig1 libgd3 libjbig0 libjpeg-turbo8 libjpeg8 libtiff5 libvpx3 libxpm4 libxslt1.1 nginx-common nginx-core Use 'sudo apt autoremove' to remove them. The following packages will be REMOVED: nginx* 0 upgraded, 0 newly installed, 1 to remove and 205 not upgraded. 2 not fully installed or removed. After this operation, 37.9 kB disk space will be freed. Do you want to continue? [Y/n] y (Reading database ... 66386 files and directories currently installed.) Removing nginx (1.10.3-0ubuntu0.16.04.2) ... Setting up nginx-core (1.10.3-0ubuntu0.16.04.2) ... Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details. invoke-rc.d: initscript nginx, action "start" failed. dpkg: error processing package nginx-core (--configure): subprocess installed post-installation script returned error exit status 1 Errors were encountered while processing: nginx-core E: Sub-process /usr/bin/dpkg returned an error code (1)
Reading package lists... Done Building dependency tree Reading state information... Done The following packages will be REMOVED: fontconfig-config fonts-dejavu-core libfontconfig1 libgd3 libjbig0 libjpeg-turbo8 libjpeg8 libtiff5 libvpx3 libxpm4 libxslt1.1 nginx-common nginx-core 0 upgraded, 0 newly installed, 13 to remove and 205 not upgraded. 1 not fully installed or removed. After this operation, 9,745 kB disk space will be freed. Do you want to continue? [Y/n] y (Reading database ... 66383 files and directories currently installed.) Removing nginx-core (1.10.3-0ubuntu0.16.04.2) ... Removing libgd3:amd64 (2.1.1-4ubuntu0.16.04.8) ... Removing libfontconfig1:amd64 (2.11.94-0ubuntu1.1) ... Removing fontconfig-config (2.11.94-0ubuntu1.1) ... Removing fonts-dejavu-core (2.35-1) ... Removing libtiff5:amd64 (4.0.6-1ubuntu0.2) ... Removing libjbig0:amd64 (2.1-3.1) ... Removing libjpeg8:amd64 (8c-2ubuntu8) ... Removing libjpeg-turbo8:amd64 (1.4.2-0ubuntu3) ... Removing libvpx3:amd64 (1.5.0-2ubuntu1) ... Removing libxpm4:amd64 (1:3.5.11-1ubuntu0.16.04.1) ... Removing libxslt1.1:amd64 (1.1.28-2.1ubuntu0.1) ... Removing nginx-common (1.10.3-0ubuntu0.16.04.2) ... Processing triggers for libc-bin (2.23-0ubuntu9) ... Processing triggers for man-db (2.7.5-1) ...
筛选已安装软件包中与 nginx 有关的
1 2 3
$ dpkg --get-selections | grep nginx
nginx-common deinstall
卸载nginx-common不保留配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14
$ sudo apt-get --purge remove nginx-common
Reading package lists... Done Building dependency tree Reading state information... Done The following packages will be REMOVED: nginx-common* 0 upgraded, 0 newly installed, 1 to remove and 205 not upgraded. After this operation, 0 B of additional disk space will be used. Do you want to continue? [Y/n] y (Reading database ... 66243 files and directories currently installed.) Removing nginx-common (1.10.3-0ubuntu0.16.04.2) ... Purging configuration files for nginx-common (1.10.3-0ubuntu0.16.04.2) ... dpkg: warning: while removing nginx-common, directory '/var/www/html' not empty so not removed
重新安装 nginx
1 2
$ sudo apt-get install nginx ...
查看版本号,执行 nginx 配置文件语法检测
1 2 3 4 5 6
$ nginx -v nginx version: nginx/1.10.3 (Ubuntu)
$ sudo nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful