【问题标题】:Nginx won't start. /usr/sbin/nginx and /var/run/nginx.pid don't existNginx 无法启动。 /usr/sbin/nginx 和 /var/run/nginx.pid 不存在
【发布时间】:2014-12-19 03:22:41
【问题描述】:

我尝试使用 /etc/init.d/nginx start 访问 Nginx。它以值 0 退出,否则绝对不执行任何操作,因为 /usr/sbin/nginx 不存在。

这里是/etc/init.d/nginx

#!/bin/sh

### BEGIN INIT INFO
# Provides:       nginx
# Required-Start:    $local_fs $remote_fs $network $syslog $named
# Required-Stop:     $local_fs $remote_fs $network $syslog $named
# 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=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/nginx
NAME=nginx
DESC=nginx

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

test -x $DAEMON || exit 0

set -e

. /lib/lsb/init-functions

# We made the awk expression more precise:
# https://code.google.com/p/phusion-passenger/issues/detail?id=1060
PID=$(awk -F'[ \t;]+' '/[^#]\<pid/ {print $2}' /etc/nginx/nginx.conf)
if [ -z "$PID" ]
then
  PID=/var/run/nginx.pid
fi

# Check if the ULIMIT is set in /etc/default/nginx
if [ -n "$ULIMIT" ]; then
  # Set the ulimits
  ulimit $ULIMIT
fi

test_nginx_config() {
                $DAEMON -t $DAEMON_OPTS >/dev/null 2>&1
                retvar=$?
                if [ $retvar -ne 0 ]
                then
                        exit $retvar
                fi
}

start() {
                start-stop-daemon --start --quiet --pidfile $PID \
                        --retry 5 --exec $DAEMON --oknodo -- $DAEMON_OPTS
}

stop() {
                start-stop-daemon --stop --quiet --pidfile $PID \
                        --retry 5 --oknodo --exec $DAEMON
}

case "$1" in
        start)
                test_nginx_config
                log_daemon_msg "Starting $DESC" "$NAME"
                start
                log_end_msg $?
                ;;

        stop)
                log_daemon_msg "Stopping $DESC" "$NAME"
                stop
                log_end_msg $?
                ;;

        restart|force-reload)
                test_nginx_config
                log_daemon_msg "Restarting $DESC" "$NAME"
                stop
                sleep 1
                start
                log_end_msg $?
                ;;

        reload)
                test_nginx_config
                log_daemon_msg "Reloading $DESC configuration" "$NAME"
                start-stop-daemon --stop --signal HUP --quiet --pidfile $PID \
                        --oknodo --exec $DAEMON
                log_end_msg $?
                ;;

        configtest|testconfig)
                log_daemon_msg "Testing $DESC configuration"
                if test_nginx_config; then
                        log_daemon_msg "$NAME"
                else
                        exit $?
                fi
                log_end_msg $?
                ;;

        status)
                status_of_proc -p $PID "$DAEMON" nginx
                ;;

        *)
                echo "Usage: $NAME {start|stop|restart|reload|force-reload|status|configtest}" >&2
                exit 1
                ;;
esac

exit 0

我看到它以 0 值退出,因为 test -x $DAEMON || exit 0 行。如果我将该行注释掉,那么当它运行不存在的守护程序 (/usr/sbin/nginx) 时,脚本将在 test_nginx_config() 函数内突然停止。也没有 /usr/local/nginx/ 目录,不管它的价值。

我在这方面完全是新手,所以可能会发生一些愚蠢的简单事情,但我只需要启动它。任何帮助将不胜感激。

【问题讨论】:

  • which nginx 的结果是什么?
  • 当我运行which nginx时,没有任何东西输出到控制台。
  • 那么很可能是因为nginx没有正确安装(不在你的路径中)。你是用apt-get/yum/...还是从源码安装的?
  • 我不是一开始安装 nginx 的人。这个系统被继承了。值得注意的是,我之前在这台机器上看到过 nginx 工作。我们需要重新启动机器并重新启动 nginx,这就是我现在所处的位置。

标签: linux bash nginx


【解决方案1】:

好吧,如果这是您的启动脚本并且 nginx 曾经使用它,那么 Nginx 已被某事或某人删除。

【讨论】:

    猜你喜欢
    • 2019-12-17
    • 1970-01-01
    • 2019-10-12
    • 2017-07-21
    • 1970-01-01
    • 1970-01-01
    • 2021-06-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多