在‘/opt’中安装了支持 Passenger 的 nginx 后,为什么它无法从‘init.d’启动?

在‘/opt’中安装了支持 Passenger 的 nginx 后,为什么它无法从‘init.d’启动?

我参加了一个教程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也不起作用。

有什么建议么?

答案1

安装 Rails + NGINX + Passenger + RVM 设置的常用方法通常涉及将 nginx 放置在 /opt/nginx 中,但实际上它不会创建 init.d 启动文件。这篇博文展示了如何轻松地从利诺德

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

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

答案2

正常安装方式nginx是通过apt-get(或 Synaptic 或 SW Center),据我所知,这不会放入任何内容/opt。在这种情况下,您只需发出以下命令即可停止/启动它:

sudo service nginx start|stop|restart (etc)

如果您nginx自行安装在/opt,我怀疑它会触及/etc/init.d目录......

答案3

我建议使用Brightbox PPA提到维基百科. 这使得所有正常服务处理都像开箱service nginx start即用一样。/etc/init.d/nginx start

对于我来说,这在精确(12.04 LTS)中运行良好。

相关内容