22

我已经从一个 built-from-src nginx 1.2.6 安装转移到 Ubuntu 13.04 上的 1.4.1。

通过 Ubuntu PPA 安装,http: //wiki.nginx.org/Install#Ubuntu_PPA 。这一切都很好。

手动,我可以使用重新加载/启动/停止服务

sudo service nginx <command>

服务器重新启动后,nginx 不会自行启动。

在我之前的手动安装中,我在 /etc/init 中有一个手写的 Upstart 脚本,它运行良好。PPA 安装已经设置了一个 /etc/init.d/ 脚本,所以我想坚持使用 PPA 方法而不是破解一些东西。

可能是因为我对服务接口不是很熟悉,所以我缺少一些东西。

我还检查了 /var/log/nginx/access.log 和 error.log,在启动过程中没有看到任何记录。

我应该怎么做才能解决这个问题?

4

6 回答 6

33

sudo update-rc.d nginx enable为我工作。

于 2015-03-24T22:17:22.693 回答
19

我对 Ubuntu 没有太多经验——但你试过运行 chkconfig 吗?

你可以试试:

# sudo update-rc.d nginx defaults

或者:

# sudo apt-get install chkconfig

# sudo chkconfig nginx on
于 2013-06-25T00:48:59.927 回答
5

对于 Ubuntu:

首先检查它的状态以确保它没有出错

systemctl status nginx.service

它要么显示错误,要么显示它没有启动

如果它没有启动,那么它需要启用

sudo /etc/init.d/systemctl enable nginx
sudo reboot
于 2019-05-18T19:50:41.730 回答
2

2016 年 3 月 28 日更新

我已经提交了对 Ubuntu Upstart 脚本的小改进,这是我在下面提出的,作为对 NGinX wiki 的拉取请求。我的拉取请求已被接受并且补丁已被合并


我在 Ubuntu 14.04 LTS 上遇到了同样的问题;NginX 可以正常使用sudo service nginx restart,但在服务器启动时没有自动启动。

我按照 NGinX Ubuntu Upstart Wiki 页面的说明进行操作,但它不起作用(最初)。所以我挖了一点。首先,我发现 Ubuntu 确实尝试在启动时启动 NGinX,但失败了:

$ sudo cat /var/log/boot.log
...
* Starting nginx http daemon                                            [fail]
...

然后我找到了 initctl upstart 作业的日志文件:

$ cat /var/log/upstart/nginx.log
...
nginx: [emerg] host not found in upstream "<mydomain>:443" in /etc/nginx/sites-enabled/mydomain:2
...

所以,我发现 NGinX 启动脚本是在网络接口启动之前运行的。这个服务器故障答案给了我修复 NginX Ubuntu Upstart 脚本所需的提示。总之,一个“!” 不见了,IFACE=lo需要改成IFACE!=lo. 为方便起见,我在下面粘贴了完整的脚本:

# nginx

description "nginx http daemon"
author "George Shammas <georgyo@gmail.com>"

start on (filesystem and net-device-up IFACE!=lo)
stop on runlevel [!2345]

env DAEMON=/usr/sbin/nginx
env PID=/var/run/nginx.pid

expect fork
respawn
respawn limit 10 5
#oom never

pre-start script
        $DAEMON -t
        if [ $? -ne 0 ]
                then exit $?
        fi
end script

exec $DAEMON

重新启动后,我检查了 NGinX 现在是否正在运行:

$ sudo initctl list | grep nginx
nginx start/running, process 1551

我会通知这个脚本的作者我的发现。

于 2016-03-12T10:50:51.920 回答
0

sudo apt-get update --fix-missing对我来说,这是因为我在安装之前没有做sudo apt-get install nginx

架构:armv7l

操作系统:rasplite

于 2019-12-19T18:49:37.247 回答
0

除了 Visionscaper 答案之外,从标准可信赖存储库安装的 nginx 使用 sysvinit 服务文件而不是新贵之一。因此而不是 nginx 服务为 upstart 编辑 rc-sysinit upstart 服务。为此使用新贵覆盖是个好主意:

# echo "start on (filesystem and net-device-up IFACE!=lo) or failsafe-boot" > /etc/init/rc-sysinit.override
于 2016-06-16T17:02:56.223 回答