【问题标题】:NGINX installation errorNGINX安装错误
【发布时间】:2018-11-09 00:30:29
【问题描述】:

使用 Linux Mint 18.3 当我安装了运行良好的 nginx 时。 由于某种原因我需要卸载它,我使用命令卸载它:

sudo apt purge nginx -y
sudo rm -rf /etc/nginx
sudo apt autoremove

然后当我以后再次需要它时,我尝试了:

sudo apt install nginx -y

它告诉我以下错误: 这是来自终端的所有行:

sudo apt install nginx -y
Reading package lists... Done
Building dependency tree       
Reading state information... Done
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 0 not upgraded.
Need to get 0 B/458 kB of archives.
After this operation, 1,482 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Preconfiguring packages ...
Selecting previously unselected package nginx-common.
(Reading database ... 235105 files and directories currently installed.)
Preparing to unpack .../nginx-common_1.10.3-0ubuntu0.16.04.2_all.deb ...
Unpacking nginx-common (1.10.3-0ubuntu0.16.04.2) ...
Selecting previously unselected package nginx-core.
Preparing to unpack .../nginx-core_1.10.3-0ubuntu0.16.04.2_amd64.deb ...
Unpacking nginx-core (1.10.3-0ubuntu0.16.04.2) ...
Selecting previously unselected package nginx.
Preparing to unpack .../nginx_1.10.3-0ubuntu0.16.04.2_all.deb ...
Unpacking nginx (1.10.3-0ubuntu0.16.04.2) ...
Processing triggers for ureadahead (0.100.0-19) ...
ureadahead will be reprofiled on next reboot
Processing triggers for ufw (0.35-0ubuntu2) ...
Processing triggers for systemd (229-4ubuntu21.2) ...
Setting up nginx-common (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.
● 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 Tue 2018-05-29 22:56:08 +06; 18ms ago
  Process: 2929 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)

May 29 22:56:08 ahs-pc systemd[1]: Starting A high performance web server a.....
May 29 22:56:08 ahs-pc nginx[2929]: nginx: [emerg] open() "/etc/nginx/nginx...y)
May 29 22:56:08 ahs-pc nginx[2929]: nginx: configuration file /etc/nginx/ng...ed
May 29 22:56:08 ahs-pc systemd[1]: nginx.service: Control process exited, c...=1
May 29 22:56:08 ahs-pc systemd[1]: Failed to start A high performance web s...r.
May 29 22:56:08 ahs-pc systemd[1]: nginx.service: Unit entered failed state.
May 29 22:56:08 ahs-pc systemd[1]: nginx.service: Failed with result 'exit-...'.
Hint: Some lines were ellipsized, use -l to show in full.
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.
  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
Errors were encountered while processing:
 nginx-core
 nginx
E: Sub-process /usr/bin/dpkg returned an error code (1)

我也尝试过强制安装,如下所示:

sudo apt install -f nginx

但抛出同样的错误!

【问题讨论】:

  • 请通过分享您的配置来详细说明。

标签: ubuntu nginx linux-mint


【解决方案1】:

我遇到了同样的问题,但我的情况有点不同,因为我正在运行 nginx-proxyacme_helper docker container,它创建了一个 nginx conf 文件并保存了该目录。

我通过从@ZontarZon 运行这些命令解决了这个问题

sudo apt-get --purge remove nginx-*
sudo apt-get install nginx

【讨论】:

    【解决方案2】:
    user@user:~$ sudo service apache2 stop
    user@user:~$ sudo apt install nginx -y
    

    【讨论】:

    • 这如何解决 OP 的问题?它只是显示你在系统上做了什么。
    • 它的工作方式相同,你应该停止 Apache 安装 nginx
    • 将其添加到您的答案中。
    【解决方案3】:

    去看看你的 error.log 文件,它位于 /var/log/nginx/error.log。我曾经有一个非常相似的错误输出,结果证明,我有其他东西运行端口 80 作为默认值。通常 apache 是罪魁祸首。

    如果您的 error.log 吐出类似于 listen() to 0.0.0.0:80, backlog 511 failed (98: Address already in use) 的内容,请尝试使用 sudo lsof -i :80 并查看端口 80 运行的内容(如果是这种情况)。如果你想让 nginx 正常运行,你必须杀死端口上的任何东西。

    另一种可能是您不小心删除了您的 nginx.conf 文件或包含该文件的目录,在这种情况下我运行了这些:

    sudo apt-get --purge remove nginx-*
    sudo apt-get install nginx
    

    如果这些都不起作用,请发布 error.log 结果。

    【讨论】: