[Fixed]-Can't restart nginx

34👍

Try:

$ sudo fuser -k 80/tcp ; sudo /etc/init.d/nginx restart 

6👍

This worked for me

sudo fuser -k 80/tcp

And then

service nginx start

Source: https://rtcamp.com/tutorials/nginx/troubleshooting/emerg-bind-failed-98-address-already-in-use/

2👍

Daemontools starting nginx successfully, then nginx daemonizes, and then daemontools tries to start nginx again, unsuccessfully, logging an error to the log.

The solution to this problem is to disable daemon mode in the main section of the nginx.conf:

daemon off;

Site: http://wiki.nginx.org/CoreModule

👤tquang

1👍

Tired with nginx restart issues and “address in use” faults. Decided to make it work once and for all.

Added just one line at the end stop and restart action in /etc/init.d/nginx file

nginx -s quit

so it looks now like (and ensure that nginx folder is in PATH variable, otherwise specify the full path)

stop)
    echo -n "Stopping $DESC: "
    start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
        --exec $DAEMON || true
    echo "$NAME."
    nginx -s quit
    ;;

restart|force-reload)
    echo -n "Restarting $DESC: "
    start-stop-daemon --stop --quiet --pidfile \
        /var/run/$NAME.pid --exec $DAEMON || true
    nginx -s quit
    sleep 1
    test_nginx_config
    start-stop-daemon --start --quiet --pidfile \
        /var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS || true
    echo "$NAME."
    ;;

Hope that this solution will work for others.

0👍

Always test your config first, it will show syntax errors and duplicate lines and point you there.

nginx -t

You will see logs there showing you what is causing the failure.

0👍

It’s because you aren’t restarting as root.

Change to root:

sudo -i

Restart:

service nginx restart

Or:

/etc/init.d/nginx restart
👤Tom

Leave a comment