在“ / opt”中安装了带乘客支持的Nginx之后,为什么它不从“ init.d”开始?


15

我经历了一个教程http://craiccomputing.blogspot.com/2010/10/passenger-3-nginx-and-rvm-on-mac-os-x.html,一切正常。没有错误。

Nginx with Passenger support was successfully installed.

The Nginx configuration file (/opt/nginx/conf/nginx.conf)
must contain the correct configuration options in order for Phusion Passenger
to function correctly.

This installer has already modified the configuration file for you! The
following configuration snippet was inserted:

  http {
      ...
      passenger_root /home/alex/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.14;
      passenger_ruby /home/alex/.rvm/wrappers/ruby-1.9.3-p194/ruby;
      ...
  }

After you start Nginx, you are ready to deploy any number of Ruby on Rails
applications on Nginx.

但是我无法启动。

alex@ubuntu:~$ sh -x /etc/init.d/nginx start
sh: 0: Can't open /etc/init.d/nginx

sudo /etc/init.d/nginx start
sudo: /etc/init.d/nginx: command not found

该目录opt/nginx存在,并且其中包含文件。Localhost:80也不起作用。

有什么建议么?

Answers:


3

安装Nginx的正常方法是通过apt-get(或Synaptic或SW Center)安装/opt,而AFAIK 中没有放置任何内容。在这种情况下,您可以通过简单地发出以下命令来停止/启动它:

sudo service nginx start|stop|restart (etc)

如果您nginx将自己安装在中/opt,我怀疑它是否会触及该/etc/init.d目录...


1
它说“ nginx:无法识别的服务”
Alex Malex 2012年

1
sudo apt-get install nginx
ish 2012年

1
为什么?它之前曾说过“成功安装了带乘客支持的Nginx。”
Alex Malex 2012年

2
您正在学习Mac教程,该教程明确说nginx直接从开始,sudo然后从停止killall,然后您问为什么未将其安装为服务!?
ish 2012年

2
我相信OP在问的是nginx +乘客,而不是香草nginx。
user10962

20

安装Rails + NGINX + Passenger + RVM安装程序的通常方法通常是将nginx放在/ opt / nginx中,但实际上它不会创建init.d启动文件。这篇博客文章展示了如何轻松地从Linode那里抢一个

wget -O init-deb.sh https://www.linode.com/docs/assets/660-init-deb.sh
sudo mv init-deb.sh /etc/init.d/nginx
sudo chown root:root /etc/init.d/nginx
sudo chmod +x /etc/init.d/nginx
sudo /usr/sbin/update-rc.d -f nginx defaults

为了后代,这是Linode的脚本:

#! /bin/sh

### BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the nginx web server
# Description:       starts nginx using start-stop-daemon
### END INIT INFO

PATH=/opt/nginx/sbin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/opt/nginx/sbin/nginx
NAME=nginx
DESC=nginx

test -x $DAEMON || exit 0

# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
        . /etc/default/nginx
fi

set -e

case "$1" in
  start)
        echo -n "Starting $DESC: "
        start-stop-daemon --start --quiet --pidfile /opt/nginx/logs/$NAME.pid \
                --exec $DAEMON -- $DAEMON_OPTS
        echo "$NAME."
        ;;
  stop)
        echo -n "Stopping $DESC: "
        start-stop-daemon --stop --quiet --pidfile /opt/nginx/logs/$NAME.pid \
                --exec $DAEMON
        echo "$NAME."
        ;;
  restart|force-reload)
        echo -n "Restarting $DESC: "
        start-stop-daemon --stop --quiet --pidfile \
                /opt/nginx/logs/$NAME.pid --exec $DAEMON
        sleep 1
        start-stop-daemon --start --quiet --pidfile \
                /opt/nginx/logs/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS
        echo "$NAME."
        ;;
  reload)
          echo -n "Reloading $DESC configuration: "
          start-stop-daemon --stop --signal HUP --quiet --pidfile     /opt/nginx/logs/$NAME.pid \
              --exec $DAEMON
          echo "$NAME."
          ;;
      *)
            N=/etc/init.d/$NAME
            echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
            exit 1
            ;;
    esac

    exit 0

需要注意的一件事:如果您更改了nginx.pid位置(默认位置为/ opt / nginx / log,我将我的位置更改为/ var / run),则需要在此文件中对其进行更改。在顶部附近,只需将其声明为变量即可:

PIDPATH=/var/run/$NAME.pid

并用$ PIDPATH替换具有pid路径的任何位置。(即使您保留原始路径,这也会使脚本更具可读性)。


1

我建议使用Brightbox Wiki中提到的Brightbox PPA。这使得像所有正常的业务交接或开箱。service nginx start/etc/init.d/nginx start

这对我来说精确(12.04 LTS)很好。


1
好建议。注意:初始化文件的URL已永久移至https://www.linode.com/docs/assets/660-init-deb.sh
Teemu Leisti 2014年
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.