Question

Error when starting Nginx

I have been following the instructions on this article:

https://www.digitalocean.com/community/tutorials/how-to-install-rails-and-nginx-with-passenger-on-ubuntu

When I enter the command on Step Seven—Start nginx I get the following error:

sudo service nginx start /etc/init.d/nginx: 2: /etc/init.d/nginx: Syntax error: newline unexpected

When inspecting the /etc/init.d/nginx file it is just an html welcome page.

I’m a newbie to nginx and don’t know how to resolve this. Can anyone provide some help?


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

yes, you are getting an error 400 and that’s what is storing on the file, no the real script. What is weird is I can access the file at http://library.linode.com/assets/660-init-deb.sh so you droplet must be having trouble accessing that host from linode.

So, I will recommend you installing Nginx from a Repo, there is reason why repos exist. is to have the latest and fully functional approved package by your OS maker, maybe not the newest, but is the one they know it works like it should on your OS. pretty sure ubuntu has a pretty recent version on its repos, I use CentOs and even with a not so new version of Nginx I can be sure is pretty reliable.

Now if you still want to do as some random person suggest and use scripts and stuff modified or made by others without knowing whats on it, here is the content of the file at http://library.linode.com/assets/660-init-deb.sh

#! /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

Just copy to the file manually and continue with the tutorial where you left.

try again wget -O init-deb.sh http://library.linode.com/assets/660-init-deb.sh my guess is you type it wrong first time and you got a 404 error, so thats what was saved to the init-deb.sh file

This comment has been deleted