Failed to start nginx high performance web server subject ошибка юнита nginx service


1

2

здравствуйте, уважаемые участники.

на голом впс я ставлю nginx+apache…. и уже выполнил давно команду:

apt-get install nginx

он дал ошибки, и после этого не ставятся пакеты, например этот:

# apt-get install libapache2-mod-rpaf
Чтение списков пакетов… Готово
Построение дерева зависимостей       
Чтение информации о состоянии… Готово
Уже установлена самая новая версия libapache2-mod-rpaf.
обновлено 0, установлено 0 новых пакетов, для удаления отмечено 0 пакетов, и 0 пакетов не обновлено.
не установлено до конца или удалено 2 пакетов.
После данной операции, объём занятого дискового пространства возрастёт на 0 B.
Хотите продолжить? [Д/н] y
Настраивается пакет nginx-full (1.6.2-5) …
Job for nginx.service failed. See 'systemctl status nginx.service' and 'journalctl -xn' for details.
invoke-rc.d: initscript nginx, action "start" failed.
dpkg: ошибка при обработке пакета nginx-full (--configure):
 подпроцесс установлен сценарий post-installation возвратил код ошибки 1
dpkg: зависимости пакетов не позволяют настроить пакет nginx:
 nginx зависит от nginx-full (>= 1.6.2-5) | nginx-light (>= 1.6.2-5) | nginx-extras (>= 1.6.2-5), однако:
  Пакет nginx-full пока не настроен.
  Пакет nginx-light не установлен.
  Пакет nginx-extras не установлен.
 nginx зависит от nginx-full (<< 1.6.2-5.1~) | nginx-light (<< 1.6.2-5.1~) | nginx-extras (<< 1.6.2-5.1~), однако:
  Пакет nginx-full пока не настроен.
  Пакет nginx-light не установлен.
  Пакет nginx-extras не установлен.

dpkg: ошибка при обработке пакета nginx (--configure):
 проблемы зависимостей — оставляем не настроенным
При обработке следующих пакетов произошли ошибки:
 nginx-full
 nginx
E: Sub-process /usr/bin/dpkg returned an error code (1)

я нигде не нашел и все советы в рунете становятся нерабочими с этой ошибкой.

I try to start this service but i can´t, the error below occur:

root@zabbix:/home/appliance# systemctl status nginx.service

nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Wed 2018-07-25 18:33:26 UTC; 1min 27s ago
  Process: 30040 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
  Process: 30037 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)

Jul 25 18:33:25 zabbix nginx[30040]: nginx: [emerg] listen() to [::]:80, backlog 511 failed (98: Address already in use)
Jul 25 18:33:25 zabbix nginx[30040]: nginx: [emerg] listen() to 0.0.0.0:80, backlog 511 failed (98: Address already in use)
Jul 25 18:33:25 zabbix nginx[30040]: nginx: [emerg] listen() to [::]:80, backlog 511 failed (98: Address already in use)
Jul 25 18:33:26 zabbix nginx[30040]: nginx: [emerg] listen() to 0.0.0.0:80, backlog 511 failed (98: Address already in use)
Jul 25 18:33:26 zabbix nginx[30040]: nginx: [emerg] listen() to [::]:80, backlog 511 failed (98: Address already in use)
Jul 25 18:33:26 zabbix nginx[30040]: nginx: [emerg] still could not bind()
Jul 25 18:33:26 zabbix systemd[1]: nginx.service: Control process exited, code=exited status=1

Jul 25 18:33:26 zabbix systemd[1]: *******Failed to start A high performance web server*** and a reverse proxy server.****

Jul 25 18:33:26 zabbix systemd[1]: nginx.service: Unit entered failed state.
Jul 25 18:33:26 zabbix systemd[1]: nginx.service: Failed with result 'exit-code'.

Richie Thomas's user avatar

asked Jul 25, 2018 at 18:43

Cibele's user avatar

You already have a process bound to the HTTP port 80 (Specially after upgrading systems! it will start apache2 by default)

So try this first :

sudo service apache2 stop
sudo systemctl restart nginx

If the problem is not solved then run this command sudo lsof -i:80 to get a list of processes using the port and then stop or disable web server.

Try to stop the process which are using the port 80 using :

sudo fuser -k 80/tcp
sudo systemctl restart nginx

In some cases it may be some issues in the configuration file.

You can use nginx -t -c /etc/nginx/nginx.conf command to find any miss-configuration.

In some cases this error is caused by a default Nginx site already on port 80, removing default config works if you don’t need a default one.

sudo rm /etc/nginx/sites-enabled/default
sudo service nginx restart

answered May 31, 2020 at 12:13

Mahdi Younesi's user avatar

Mahdi YounesiMahdi Younesi

6,7892 gold badges20 silver badges51 bronze badges

5

For me this error was caused by a default nginx site already on port 80. Removing default site worked

sudo rm /etc/nginx/sites-enabled/default
sudo service nginx restart

answered Dec 13, 2019 at 21:54

Vladislav Povorozniuc's user avatar

1

You already have a process bound to the HTTP port 80.
You can run command sudo lsof -i:80 to get a list of processes using the port and then stop/disable web server.

answered Jul 25, 2018 at 21:16

Valery Viktorovsky's user avatar

Try to stop the process which are using the port 80:

sudo fuser -k 80/tcp

snoob dogg's user avatar

snoob dogg

2,4083 gold badges29 silver badges53 bronze badges

answered Feb 18, 2019 at 11:01

shrikant joshi's user avatar

2

Try to stop the process which is using port 80:

sudo fuser -k 80/tcp

When you did restart using

sudo systemctl restart nginx

answered Sep 26, 2020 at 5:01

Sudhan's user avatar

SudhanSudhan

1993 silver badges13 bronze badges

It may be some issues in the configuration file. You can use this
nginx -t -c /etc/nginx/nginx.confcommand to find any bugs in the configuration file. If you find the bugs resolve that run the sudo service nginx restart again. It will work.

Please check the reference here

answered Nov 1, 2019 at 8:19

sanzmalz's user avatar

sanzmalzsanzmalz

4384 silver badges12 bronze badges

I had to use:

sudo killall nginx 

And could then use;

sudo systemctl start nginx

benson23's user avatar

benson23

15.7k9 gold badges18 silver badges38 bronze badges

answered Feb 24, 2022 at 21:44

mututa paul's user avatar

0

In my experience, this error can be triggered in several different situations (which might have the same root, but are perceived as different scenarios).

Not only port 80

Depending on your nginx config, you should also try port 443:

  • sudo lsof -i:80
  • sudo lsof -i:443

You should be able to check your nginx listen ports in /etc/nginx/sites-enabled (under Debian)

Special case

In my case, there was an nginx instance running, that would block itself from restarting. It would not go down with sudo systemctl stop nginx. I had to use sudo killall nginx and could then use sudo systemctl start nginx.

Config error

I also experienced the exact same error message on a config error.

You can check your nginx config with /usr/sbin/nginx -c /etc/nginx/nginx.conf@ (this will also test all virtual host files (/etc/nginx/sites-enabled`)

answered Sep 13, 2020 at 8:59

DarkTrick's user avatar

DarkTrickDarkTrick

2,2831 gold badge19 silver badges35 bronze badges

For me stopping apache service solved the problem
sudo service apache2 stop

answered Oct 31, 2020 at 3:38

sudayn's user avatar

sudaynsudayn

1,12411 silver badges14 bronze badges

0

i had same issue, was because i have apache and nginx on same server !
so when i typed sudo reboot it didn’t work because it started apache while am using nginx so i just run this two commands

sudo systemctl stop apache2
then
sudo systemctl start nginx

then sudo systemctl disable apache2
so next time i reboot not going to face same issue

help from aws services support

answered Dec 2, 2020 at 23:38

ABDULLAH MAKKI's user avatar

1

I had this problem too. I checked the /etc/nginx/site-available/default file and I have forgotten to close the bracket (syntax error).

סטנלי גרונן's user avatar

סטנלי גרונן

2,90723 gold badges46 silver badges68 bronze badges

answered May 8, 2020 at 4:43

sadra hakim's user avatar

Just restart the nginx server. It should resolve your problem
sudo systemctl restart nginx

answered Oct 22, 2022 at 14:05

jttafda's user avatar

I was using gunicorn with nginx, found that service was not active.

sudo systemctl enable gunicorn.socket
sudo systemctl start gunicorn.socket
sudo systemctl restart nginx

Worked for me.

if your gunicorn is active, please make sure it’s working fine.

you can also go through the logs(errors) via nginx logs from

sudo tail -f /var/log/nginx/error.log

answered Aug 20, 2022 at 11:56

Harshit Jain's user avatar

In my experience, I tried sudo systemctl stop nginx and also attempted to kill the Nginx processes using their PIDs but they were still running and listening on port 80, which indicates that there might be another service or process that is automatically restarting Nginx.

To troubleshoot this issue, I did these steps:

  • I identify the parent process by running the following command to identify the parent process of the Nginx processes:

    ps -o ppid= -p <PID>

I replaced with one of the Nginx process IDs.
The output gave me the parent process ID (PPID) for each Nginx process, and sudo kill <PPID> solved the issue.

You can also try this:

  1. Determine the parent process name: Run the following command to find the name of the parent process: ps -p <PPID> -o comm=
    Replace with the parent process ID obtained in the previous step. Repeat this command for each PPID you have.
    The output will give you the name of the parent process associated with each Nginx process.

  2. Stop the parent process: Once you have identified the parent process, try stopping it using the appropriate method.
    For example, if the parent process is Apache, you can use sudo systemctl stop apache or if it is another web server, you can stop it using the corresponding command.

answered May 31 at 14:20

Reza Pourrahim's user avatar

Mine was caused by an inability to find the ssl cert. I found this by running:

nginx -t -c /etc/nginx/nginx.conf

This was a permissions issue for me and I did this to «fix» it:

sudo chmod 700 /etc/letsencrypt/live/ -R

answered Jun 6 at 3:21

gabeyww's user avatar

Table of Contents
Hide
  1. Reasons of this error
  2. Solutions

    1. 1. nginx: [emerg] listen() to [::]:80, backlog 511 failed (98: Address already in use)
    2. 2. nginx: [emerg] unexpected end of file, expecting “;” or “}” in /etc/nginx/c>
    3. 3. nginx: [emerg] a duplicate default server for [::]:80 in /etc/nginx/sites-enabled/default
    4. 4. nginx: [emerg] unknown directive “stream” in /etc/nginx/nginx.conf
    5. 5. nginx: [emerg] directive “root” is not terminated by “;” in /etc/nginx/conf.d/writefreely.conf:6
    6. 6. Error in configuration file
  3. Conclusion

    1. Related Posts

You run the command systemctl status nginx.service or sudo systemctl start nginx and bam, you got a scary multi lines error stating that nginx failed to start high performance web server and a reverse proxy server. In this article we will focus on resolving this issue completely.

Reasons of this error

The error is generic. It means there could be multiple reasons for nginx failing to start. Your error logs will show you the reason as to why this is happening. Some of them are –

  • nginx: [emerg] listen() to [::]:80, backlog 511 failed (98: Address already in use)
  • nginx: [emerg] unexpected end of file, expecting “;” or “}” in /etc/nginx/c>
  • nginx: [emerg] a duplicate default server for [::]:80 in /etc/nginx/sites-enabled/default
  • nginx: [emerg] unknown directive “stream” in /etc/nginx/nginx.conf
  • nginx: [emerg] directive “root” is not terminated by “;” in /etc/nginx/conf.d/writefreely.conf:6
  • Others..

Let’s look at each of these errors and solve them.

Solutions

1. nginx: [emerg] listen() to [::]:80, backlog 511 failed (98: Address already in use)

This error appears when the nginx port i.e. 80 and 443 are occupied by some other process like Apache. The solution is to kill all the process which are running on these ports and let nginx use them.

First get the list of all the processes that are running on port 80 –

sudo lsof -i:80

Next, we will stop all these processes –

sudo fuser -k 80/tcp

If apache2 is running on this port then you may also stop it directly –

sudo service apache2 stop

Now you may start your nginx server –

sudo service nginx restart

2. nginx: [emerg] unexpected end of file, expecting “;” or “}” in /etc/nginx/c>

This error shows that there is some syntax error in config file. Open the indicated file at /etc/nginx/ and check for the syntax errors in the file.

3. nginx: [emerg] a duplicate default server for [::]:80 in /etc/nginx/sites-enabled/default

This error arises when you have multiple nginx websites running. Since they all are using the same 80 port so there is a clash. The solution is to change ports or if you can disable them like default website, then do that.

First remove or unlink the default website –

sudo unlink /etc/nginx/sites-enabled/default

# OR

sudo rm /etc/nginx/sites-enabled/default

Restart the nginx server –

sudo service nginx restart

4. nginx: [emerg] unknown directive “stream” in /etc/nginx/nginx.conf

nginx use the stream module and if we load it dynamically then nginx fails to start and throw this error. To resolve it, you need to statically add the stream module.

First open the nignx.conf file located at /etc/nignx/nginx.conf and add the below code at the very top of this file –

load_module /usr/lib/nginx/modules/ngx_stream_module.so;

Here you need to check whether this ngx_stream_module is located in lib or lib64 on your operating system. In CentOS it is in lib64. So, the address will change to –

load_module /usr/lib64/nginx/modules/ngx_stream_module.so;

Then save the nginx.conf file and run these commands in your terminal –

nginx -t
nginx -s reload
service nginx restart

5. nginx: [emerg] directive “root” is not terminated by “;” in /etc/nginx/conf.d/writefreely.conf:6

This is again a syntax error in a file. It is saying that “root” is not terminated by semicolon. So, solution is to open the file located at /etc/nginx/conf.d/writefreely.conf, move to line number 6 and add a semicolon at the end.

6. Error in configuration file

If there is some error in configuration file then you can understand it by running this command –

nginx -t -c /etc/nginx/nginx.conf

Once you find the bug, you can resolve it and then restart the nginx server –

sudo service nginx restart

Conclusion

In this article we saw various reasons for error “nginx: failed to start high performance web server and a reverse proxy server”. In your case, the reason could be different but solution will be one of our provided ones.

This is Akash Mittal, an overall computer scientist. He is in software development from more than 10 years and worked on technologies like ReactJS, React Native, Php, JS, Golang, Java, Android etc. Being a die hard animal lover is the only trait, he is proud of.

Related Tags
  • Error,
  • nginx

systemctl status nginx.service outputs:

    ● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Wed 2019-01-23 19:04:12 +03; 1min 1s ago
     Docs: man:nginx(8)
  Process: 10511 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)

Jan 23 19:04:12 linux systemd[1]: Starting A high performance web server and a reverse proxy server...
Jan 23 19:04:12 linux nginx[10511]: nginx: [emerg] a duplicate default server for [::]:80 in /etc/nginx/sites-enabled/default:23
Jan 23 19:04:12 linux nginx[10511]: nginx: configuration file /etc/nginx/nginx.conf test failed
Jan 23 19:04:12 linux systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
Jan 23 19:04:12 linux systemd[1]: nginx.service: Failed with result 'exit-code'.
Jan 23 19:04:12 linux systemd[1]: Failed to start A high performance web server and a reverse proxy server.

journalctl -xe outputs:

-- Defined-By: systemd
-- Support: https://www.debian.org/support
-- 
-- An ExecStartPre= process belonging to unit nginx.service has exited.
-- 
-- The process' exit code is 'exited' and its exit status is 1.
Jan 23 19:10:15 linux systemd[1]: nginx.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: https://www.debian.org/support
-- 
-- The unit nginx.service has entered the 'failed' state with result 'exit-code'.
Jan 23 19:10:15 linux systemd[1]: Failed to start A high performance web server and a reverse proxy server.
-- Subject: A start job for unit nginx.service has failed
-- Defined-By: systemd
-- Support: https://www.debian.org/support
-- 
-- A start job for unit nginx.service has finished with a failure.
-- 
-- The job identifier is 2656 and the job result is failed.
Jan 23 19:10:15 linux sudo[10625]: pam_unix(sudo:session): session closed for user root
Jan 23 19:10:23 linux sudo[10631]:  lvlzyro : TTY=pts/0 ; PWD=/home/lvlzyro ; USER=root ; COMMAND=/usr/bin/journalctl -xe
Jan 23 19:10:23 linux sudo[10631]: pam_unix(sudo:session): session opened for user root by (uid=0)

nginx.conf:

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}


#mail {
#   # See sample authentication script at:
#   # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
#   # auth_http localhost/auth.php;
#   # pop3_capabilities "TOP" "USER";
#   # imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#   server {
#       listen     localhost:110;
#       protocol   pop3;
#       proxy      on;
#   }
# 
#   server {
#       listen     localhost:143;
#       protocol   imap;
#       proxy      on;
#   }
#}

What should I do to fix it? Thanks for your attention btw.

After a dist-upgrade on my debian machine yesterday I am having some problems with the nginx init script. Whenever I try to start nginx using the init script it comes up with a error message:

# service nginx start
Job for nginx.service failed. See 'systemctl status nginx.service' and 'journalctl -xn' for details.

Output of systemctl status nginx.service:

# systemctl status nginx.service
● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled)
   Active: failed (Result: exit-code) since Tue 2015-05-19 12:36:12 CEST; 7s ago
  Process: 14087 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
  Process: 14126 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=203/EXEC)

Output of journalctl -xn:

# journalctl -xn
systemd[1]: nginx.service never wrote its PID file. Failing.
systemd[1]: Failed to start A high performance web server and a reverse proxy server.
-- Subject: Unit nginx.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit nginx.service has failed.
--
-- The result is failed.
systemd[1]: Unit nginx.service entered failed state.
systemd[14126]: Failed at step EXEC spawning /usr/sbin/nginx: No such file or directory
-- Subject: Process /usr/sbin/nginx could not be executed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- The process /usr/sbin/nginx could not be executed and failed.
--
-- The error number returned while executing this process is 2.
systemd[1]: nginx.service: control process exited, code=exited status=203
systemd[1]: Failed to start A high performance web server and a reverse proxy server.
-- Subject: Unit nginx.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit nginx.service has failed.
--
-- The result is failed.
systemd[1]: Unit nginx.service entered failed state.

my nginx file in init.d:

#! /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=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/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

. /lib/lsb/init-functions

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

exit 0

The nginx daemon file is located in /usr/local/sbin/nginx (I compiled it there).

Things i’ve tried so far:
I copied the daemon file /usr/local/sbin/nginx to /usr/sbin/nginx

When I use service nginx start it hangs on starting nginx. When I try to connect to port 80 it does work. So I proceeded to edit my init script and change PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin to PATH=/usr/sbin:/usr/bin:/sbin:/bin:/usr/sbin:/usr/bin. This however gave the same result.

I haven’t triedd anything else so far.

  • Failed to execute msu package ошибка
  • Failed to create winpe file ошибка lazesoft
  • Failed to create opengl context ошибка
  • Failed to create dir divinity original sin 2 ошибка
  • Failed to create aac streaming encoder simple output ошибка