尝试安装 nginx 时出现“子进程 /usr/bin/dpkg 返回错误代码 (1)”

尝试安装 nginx 时出现“子进程 /usr/bin/dpkg 返回错误代码 (1)”

我正在尝试安装nginx,但收到以下错误消息:

kurt@kurt-ThinkPad:~$ sudo apt-get install nginx
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  gyp libjs-inherits libjs-node-uuid libuv1 libuv1-dev linux-headers-4.4.0-47
  linux-headers-4.4.0-47-generic linux-image-4.4.0-47-generic
  linux-image-extra-4.4.0-47-generic node-abbrev node-ansi
  node-ansi-color-table node-archy node-async node-block-stream
  node-combined-stream node-cookie-jar node-delayed-stream node-forever-agent
  node-form-data node-fstream node-fstream-ignore node-github-url-from-git
  node-glob node-graceful-fs node-gyp node-inherits node-ini
  node-json-stringify-safe node-lockfile node-lru-cache node-mime
  node-minimatch node-mkdirp node-mute-stream node-node-uuid node-nopt
  node-normalize-package-data node-npmlog node-once node-osenv node-qs
  node-read node-read-package-json node-request node-retry node-rimraf
  node-semver node-sha node-sigmund node-slide node-tar node-tunnel-agent
  node-underscore node-which
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  nginx-common nginx-core
Suggested packages:
  fcgiwrap nginx-doc
The following NEW packages will be installed:
  nginx nginx-common nginx-core
0 upgraded, 3 newly installed, 0 to remove and 9 not upgraded.
Need to get 458 kB of archives.
After this operation, 1482 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://nl.archive.ubuntu.com/ubuntu xenial-updates/main amd64 nginx-common all 1.10.0-0ubuntu0.16.04.4 [26,6 kB]
Get:2 http://nl.archive.ubuntu.com/ubuntu xenial-updates/main amd64 nginx-core amd64 1.10.0-0ubuntu0.16.04.4 [428 kB]
Get:3 http://nl.archive.ubuntu.com/ubuntu xenial-updates/main amd64 nginx all 1.10.0-0ubuntu0.16.04.4 [3498 B]
Fetched 458 kB in 0s (685 kB/s)
Preconfiguring packages ...
Selecting previously unselected package nginx-common.
(Reading database ... 501856 files and directories currently installed.)
Preparing to unpack .../nginx-common_1.10.0-0ubuntu0.16.04.4_all.deb ...
Unpacking nginx-common (1.10.0-0ubuntu0.16.04.4) ...
Selecting previously unselected package nginx-core.
Preparing to unpack .../nginx-core_1.10.0-0ubuntu0.16.04.4_amd64.deb ...
Unpacking nginx-core (1.10.0-0ubuntu0.16.04.4) ...
Selecting previously unselected package nginx.
Preparing to unpack .../nginx_1.10.0-0ubuntu0.16.04.4_all.deb ...
Unpacking nginx (1.10.0-0ubuntu0.16.04.4) ...
Processing triggers for ufw (0.35-0ubuntu2) ...
Processing triggers for ureadahead (0.100.0-19) ...
ureadahead will be reprofiled on next reboot
Processing triggers for systemd (229-4ubuntu12) ...
Setting up nginx-common (1.10.0-0ubuntu0.16.04.4) ...
Setting up nginx-core (1.10.0-0ubuntu0.16.04.4) ...
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.0-0ubuntu0.16.04.4) | nginx-full (>= 1.10.0-0ubuntu0.16.04.4) | nginx-light (>= 1.10.0-0ubuntu0.16.04.4) | nginx-extras (>= 1.10.0-0ubuntu0.16.04.4); 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.0-0ubuntu0.16.04.4.1~) | nginx-full (<< 1.10.0-0ubuntu0.16.04.4.1~) | nginx-light (<< 1.10.0-0ubuntu0.16.04.4.1~) | nginx-extras (<< 1.10.0-0ubuntu0.16.04.4.1~); 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.

dpkg: error processing package nginx (--configure):
 dependency problems - leaving No apport report written because the error message indicates its a followup error from a previous failure.
                                                         unconfigured
Processing triggers for systemd (229-4ubuntu12) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for ufw (0.35-0ubuntu2) ...
Errors were encountered while processing:
 nginx-core
 nginx
E: Sub-process /usr/bin/dpkg returned an error code (1)

以下是一段看似相关的摘录/var/log/syslog

Dec  6 12:04:47 kurt-ThinkPad systemd[1]: Started CUPS Scheduler.
Dec  6 12:04:47 kurt-ThinkPad systemd[1]: Started ACPI event daemon.
Dec  6 12:04:48 kurt-ThinkPad systemd[1]: Reloading.
Dec  6 12:04:48 kurt-ThinkPad systemd[1]: snapd.refresh.timer: Adding 5h 37min 39.335667s random time.
Dec  6 12:04:48 kurt-ThinkPad systemd[1]: Started CUPS Scheduler.
Dec  6 12:04:48 kurt-ThinkPad systemd[1]: Started ACPI event daemon.
Dec  6 12:04:48 kurt-ThinkPad systemd[1]: Reloading.
Dec  6 12:04:49 kurt-ThinkPad systemd[1]: snapd.refresh.timer: Adding 3h 39min 30.123677s random time.
Dec  6 12:04:49 kurt-ThinkPad systemd[1]: Started CUPS Scheduler.
Dec  6 12:04:49 kurt-ThinkPad systemd[1]: Started ACPI event daemon.
Dec  6 12:04:49 kurt-ThinkPad systemd[1]: Starting A high performance web server and a reverse proxy server...
Dec  6 12:04:49 kurt-ThinkPad nginx[6334]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Dec  6 12:04:49 kurt-ThinkPad nginx[6334]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Dec  6 12:04:49 kurt-ThinkPad nginx[6334]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Dec  6 12:04:49 kurt-ThinkPad nginx[6334]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Dec  6 12:04:50 kurt-ThinkPad nginx[6334]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Dec  6 12:04:50 kurt-ThinkPad nginx[6334]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Dec  6 12:04:50 kurt-ThinkPad nginx[6334]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Dec  6 12:04:50 kurt-ThinkPad nginx[6334]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Dec  6 12:04:51 kurt-ThinkPad nginx[6334]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Dec  6 12:04:51 kurt-ThinkPad nginx[6334]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Dec  6 12:04:51 kurt-ThinkPad nginx[6334]: nginx: [emerg] still could not bind()
Dec  6 12:04:51 kurt-ThinkPad systemd[1]: nginx.service: Control process exited, code=exited status=1
Dec  6 12:04:51 kurt-ThinkPad systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Dec  6 12:04:51 kurt-ThinkPad systemd[1]: nginx.service: Unit entered failed state.
Dec  6 12:04:51 kurt-ThinkPad systemd[1]: nginx.service: Failed with result 'exit-code'.

知道为什么安装不起作用吗?(类似问题的答案,E: 子进程 /usr/bin/dpkg 返回错误代码 (1) [与 Google Chrome 相关],表明某些文件已损坏)。

更新

这也是 Ubuntu 生成并发送给其开发社区的错误消息:

在此处输入图片描述

答案1

查看线路

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

这意味着已经有一个 Web 服务器正在运行(监听 nginx 所需的 80 端口)。尝试使用此命令来识别哪个进程正在使用 80 端口:

netstat -tlnp | fgrep -w :80

卸载该服务器,或重新配置它以使用 80 以外的其他端口。

答案2

首先,卸载Nginx(包括配置)

sudo apt remove --purge nginx nginx-common

现在再次安装

相关内容