nginx 无法在 Ubuntu 15.10 服务器上安装

nginx 无法在 Ubuntu 15.10 服务器上安装

我正在尝试在刚刚安装的带有 Mate 桌面的 Ubuntu Server 15.10 上安装 nginx。

我做了一个快速更新:

sudo apt-get update

现在尝试安装 nginx:

sudo apt-get install nginx

这是我得到的:

server@Node1:~/nod$ sudo apt-get install nginx
Reading package lists... Done
Building dependency tree       
Reading state information... Done
nginx is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
2 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Setting up nginx-core (1.9.3-1ubuntu1.1) ...
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.9.3-1ubuntu1.1) | nginx-full (>= 1.9.3-1ubuntu1.1) | nginx-light (>= 1.9.3-1ubuntu1.1) | nginx-extras (>= 1.9.3-1ubuntu1.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.
 nginx depends on nginx-core (<< 1.9.3-1ubuntu1.1.1~) | nginx-full (<< 1.9.3-1ubuntu1.1.1~) | nginx-light (<< 1.9.3-1ubuntu1.1.1~) | nginx-extras (<< 1.9.3-1ubuntu1.1.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 unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
Errors were encountered while processing:
 nginx-core
 nginx
E: Sub-process /usr/bin/dpkg returned an error code (1)

以下是输出systemctl status nginx.service

 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 2016-02-27 20:32:18 EST; 32min ago
  Process: 6023 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
  Process: 6020 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)

Feb 27 20:32:16 Node1 nginx[6023]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Feb 27 20:32:17 Node1 nginx[6023]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Feb 27 20:32:17 Node1 nginx[6023]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Feb 27 20:32:17 Node1 nginx[6023]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Feb 27 20:32:17 Node1 nginx[6023]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Feb 27 20:32:18 Node1 nginx[6023]: nginx: [emerg] still could not bind()
Feb 27 20:32:18 Node1 systemd[1]: nginx.service: Control process exited, code=exited status=1
Feb 27 20:32:18 Node1 systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Feb 27 20:32:18 Node1 systemd[1]: nginx.service: Unit entered failed state.
Feb 27 20:32:18 Node1 systemd[1]: nginx.service: Failed with result 'exit-code'.

这是我第一次使用 15.10,希望能更简单一些。我没有太多时间花在服务器安装上,正在考虑回滚到 14.xx。如果您有任何解决方案,请告知。

谢谢。

答案1

在您的情况下,端口 80 或端口 98 已被其他进程使用。您需要找出哪个进程正在使用这些端口,然后终止该进程或服务。

sudo netstat -nlp

然后您可以尝试启动 nginx。顺便说一下,您的例子中 nginx 已经安装好了。

您可以参考这个链接1或者链接2

答案2

如果您已经安装了 Apache。

应用以下命令。

停止 apache2

service apache2 stop

然后安装 nginx

sudo apt-get install nginx 

答案3

我遇到了同样的问题。关于 Apache 的建议不适用,因为我在安装过程中主动卸载了它。

/etc/nginx/nginx.conf事实证明,我看到的是 nginx 的配置文件和服务脚本之间发生冲突的结果/lib/systemd/system/nginx.service

具体来说,服务脚本使用一些选项启动 nginx,包括daemon on

$ cat /lib/systemd/system/nginx.service
...
[Service]
...
ExecStartPre=/usr/sbin/nginx -t -q -g 'daemon on; master_process on;'
ExecStart=/usr/sbin/nginx -g 'daemon on; master_process on;'
ExecReload=/usr/sbin/nginx -g 'daemon on; master_process on;' -s reload
...

/usr/sbin/nginx -g 'daemon on; master_process on;'直接在终端上运行,出现了以下错误:

nginx: [emerg] "daemon" directive is duplicate in /etc/nginx/nginx.conf:1

我看了一下/etc/nginx/nginx.conf并发现(第 1 行):

daemon off;

注释掉它并运行sudo apt-get -f install即可解决问题。

答案4

这是错误。您可以手动编辑修复程序。

我在 digitalocean repos 上有它。使用 virtualmin?

https://github.com/webmin/webmin/issues/206

相关内容