nginx-nginx: [emerg] bind () to [::]: 80 failed (98: адрес уже используется)

внезапно я получаю следующую ошибку nginx

 * Restarting nginx
 * Stopping nginx nginx
   ...done.
 * Starting nginx nginx
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
   ...done.
   ...done.

если я

lsof -i :80 or sudo fuser -k 80/tcp 

Я ничего не получу. Ничего на порту 80

затем я запускаю ниже:

sudo netstat -pan | grep ":80"
tcp        0      0 127.0.0.1:8070          0.0.0.0:*               LISTEN      15056/uwsgi     
tcp        0      0 10.170.35.97:39567      10.158.58.13:8080       TIME_WAIT   -               
tcp        0      0 10.170.35.97:39564      10.158.58.13:8080       TIME_WAIT   -               
tcp        0      0 10.170.35.97:39584      10.158.58.13:8080       TIME_WAIT   -               
tcp        0      0 10.170.35.97:39566      10.158.58.13:8080       TIME_WAIT   -               
tcp        0      0 10.170.35.97:39571      10.158.58.13:8080       TIME_WAIT   -               
tcp        0      0 10.170.35.97:39580      10.158.58.13:8080       TIME_WAIT   -               
tcp        0      0 10.170.35.97:39562      10.158.58.13:8080       TIME_WAIT   -               
tcp        0      0 10.170.35.97:39582      10.158.58.13:8080       TIME_WAIT   -               
tcp        0      0 10.170.35.97:39586      10.158.58.13:8080       TIME_WAIT   -               
tcp        0      0 10.170.35.97:39575      10.158.58.13:8080       TIME_WAIT   -               
tcp        0      0 10.170.35.97:39579      10.158.58.13:8080       TIME_WAIT   -               
tcp        0      0 10.170.35.97:39560      10.158.58.13:8080       TIME_WAIT   -               
tcp        0      0 10.170.35.97:39587      10.158.58.13:8080       TIME_WAIT   -               
tcp        0      0 10.170.35.97:39591      10.158.58.13:8080       TIME_WAIT   -               
tcp        0      0 10.170.35.97:39589      10.158.58.13:8080       TIME_WAIT   - 

Я в тупик.

как отлаживать?

я использую uwsgi с

пропуск прокси на порт 8070. на uwsgi работает. Nginx-это не. Я использую ubuntu 12.4

Ниже приведены соответствующие части моего nginx conf файл

upstream uwsgi_frontend {
          server 127.0.0.1:8070;
        }
server {
listen 80;
        server_name 127.0.0.1;
        location = /favicon.ico {
                  log_not_found off;
                }



                location / {
                       include uwsgi_params;
                       uwsgi_buffering off;

                       uwsgi_pass 127.0.0.1:8070;
                 }
        }

вот как я устанавливаю nginx на ubuntu 12.04

nginx=stable;add-apt-repository ppa:nginx/$nginx;
apt-get update
apt get install nginx-full

9 ответов


[::]:80 - это адрес ipv6.

эта ошибка может быть вызвана, если у вас есть конфигурация nginx, которая прослушивает порт 80, а также порт [::]:80.

у меня было следующее На моих сайтах по умолчанию-доступный файл:

listen 80;
listen [::]:80 default_server;

вы можете исправить это путем добавления ipv6only=on до [::]:80 такой:

listen 80;
listen [::]:80 ipv6only=on default_server;

для получения дополнительной информации, см.:

http://forum.linode.com/viewtopic.php?t=8580

http://wiki.nginx.org/HttpCoreModule#listen


я исправил это, запустив sudo apachectl stop - оказывается, apache работал в фоновом режиме и не позволял nginx запускать нужный порт.

на ubuntu run sudo /etc/init.d/apache2 stop


Я нашел проблему, которую у меня никогда не было раньше.

мне просто пришлось удалить /etc/nginx/sites-available/default. Потом сработало.

мой conf был в /etc/nginx/default.


Я также получал ту же ошибку. nginx: [emerg] bind () to [::]: 80 failed (98: адрес уже используется) и когда я набрал localhost в браузере, я получаю

это работает!

Это веб-страница по умолчанию для этого сервера.

программное обеспечение веб-сервера работает, но контент еще не добавлен. вместо страницы приветствия nginx apache2 работает на том же порту,

  1. найти порты apache2 не.файл conf

    sudo/etc/apache2 / ports.conf

  2. изменить порт другой, чем 80, я делаю это как 70

  3. сохраните файл

  4. перезагрузить систему

Он будет работать и для вас, если вы введете localhost в браузере, вы получите страницу приветствия nginx


мой случай отличается, мне пришлось убить запуск Nginx, чтобы перезапустить его.

вместо

sudo systemctl restart nginx

мне пришлось использовать:

sudo pkill -f nginx
sudo systemctl start nginx

попробуйте выполнить эту команду

sudo fuser -k 443/tcp
service nginx restart

у меня была такая же проблема в letsencrypt (certbot) и nginx,

ref:https://github.com/certbot/certbot/issues/5486

эта ошибка еще не имеет решения

Итак, изменен cron для обновления (поставив перезагрузить после реновации) (используя предложение от certbot)

-- in /etc/cron.d/certbot
from
0 */12 * * * root test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(3600))' && certbot -q renew 
to
0 */12 * * * root test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(3600))' && certbot -q renew --pre-hook "service nginx stop" --post-hook "service nginx start"

журналы (короткий):

-- in /var/log/syslog
Jun 10 00:14:25 localhost systemd[1]: Starting Certbot...
Jun 10 00:14:38 localhost certbot[22222]: nginx: [error] open() "/run/nginx.pid$
Jun 10 00:14:41 localhost certbot[22222]: Hook command "nginx" returned error c$
Jun 10 00:14:41 localhost certbot[22222]: Error output from nginx:
Jun 10 00:14:41 localhost certbot[22222]: nginx: [emerg] bind() to 0.0.0.0:443 $
Jun 10 00:14:41 localhost certbot[22222]: nginx: [emerg] bind() to 0.0.0.0:80 f$
Jun 10 00:14:41 localhost certbot[22222]: nginx: [emerg] bind() to 0.0.0.0:443 $
Jun 10 00:14:41 localhost certbot[22222]: nginx: [emerg] bind() to 0.0.0.0:80 f$
Jun 10 00:14:41 localhost certbot[22222]: nginx: [emerg] bind() to 0.0.0.0:443 $
Jun 10 00:14:41 localhost certbot[22222]: nginx: [emerg] bind() to 0.0.0.0:80 f$
Jun 10 00:14:41 localhost certbot[22222]: nginx: [emerg] bind() to 0.0.0.0:443 $
Jun 10 00:14:41 localhost certbot[22222]: nginx: [emerg] bind() to 0.0.0.0:80 f$
Jun 10 00:14:41 localhost certbot[22222]: nginx: [emerg] bind() to 0.0.0.0:443 $
Jun 10 00:14:41 localhost certbot[22222]: nginx: [emerg] bind() to 0.0.0.0:80 f$
Jun 10 00:14:41 localhost certbot[22222]: nginx: [emerg] still could not bind()
Jun 10 00:14:41 localhost systemd[1]: Started Certbot.


-- in /var/log/nginx/error.log
2018/06/10 00:14:27 [notice] 22233#22233: signal process started
2018/06/10 00:14:31 [notice] 22237#22237: signal process started
2018/06/10 00:14:33 [notice] 22240#22240: signal process started
2018/06/10 00:14:34 [notice] 22245#22245: signal process started
2018/06/10 00:14:38 [notice] 22255#22255: signal process started
2018/06/10 00:14:38 [error] 22255#22255: open() "/run/nginx.pid" failed (2: No $
2018/06/10 00:14:39 [emerg] 22261#22261: bind() to 0.0.0.0:443 failed (98: Addr$
2018/06/10 00:14:39 [emerg] 22261#22261: bind() to 0.0.0.0:80 failed (98: Addre$
2018/06/10 00:14:39 [emerg] 22261#22261: bind() to 0.0.0.0:443 failed (98: Addr$
2018/06/10 00:14:39 [emerg] 22261#22261: bind() to 0.0.0.0:80 failed (98: Addre$
2018/06/10 00:14:39 [emerg] 22261#22261: bind() to 0.0.0.0:443 failed (98: Addr$
2018/06/10 00:14:39 [emerg] 22261#22261: bind() to 0.0.0.0:80 failed (98: Addre$
2018/06/10 00:14:39 [emerg] 22261#22261: bind() to 0.0.0.0:443 failed (98: Addr$
2018/06/10 00:14:39 [emerg] 22261#22261: bind() to 0.0.0.0:80 failed (98: Addre$
2018/06/10 00:14:39 [emerg] 22261#22261: bind() to 0.0.0.0:443 failed (98: Addr$
2018/06/10 00:14:39 [emerg] 22261#22261: bind() to 0.0.0.0:80 failed (98: Addre$
2018/06/10 00:14:39 [emerg] 22261#22261: still could not bind()

У меня было несколько *.сохранение файлов (аварийных дампов из nano) из разных конфигурационных файлов NGINX на моих сайтах-avilable dir. Однажды я удалил их .сохраните файлы, nginx перезапущен нормально. Я предположил, что они безвредны, поскольку не было соответствующих символических ссылок, но я думаю, что ошибся.


первое изменение Apache listen port 80 to 8080 apache в/etc/apache2 / ports.конф включают

Listen 1.2.3.4:80 to 1.2.3.4:8080
sudo service apache2 restart 

или

sudo service httpd restart    // in case of centos

затем добавьте nginx в качестве обратного прокси-сервера, который будет слушать порт apache

server {
 listen   1.2.3.4:80;
 server_name  some.com;

 access_log  /var/log/nginx/something-access.log;

 location / {
  proxy_pass http://localhost:8080;
  proxy_redirect off;
  proxy_set_header Host $host;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 }


location ~* ^.+\.(jpg|js|jpeg|png)$ {
   root /usr/share/nginx/html/;
}

location /404.html {
  root /usr/share/nginx/html/40x.html;
}

error_page 404 /404.html;
    location = /40x.html {
}

error_page 500 502 503 504 /50x.html;
    location = /50x.html {
}

# put code for static content like js/css/images/fonts
}

после изменений перезапустите сервер nginx

sudo service nginx restart

теперь весь трафик будет обрабатываться сервером nginx и отправлять все динамические запросы в apache, а статический контент обслуживается сервером nginx.

для предварительной конфигурации, как кэш :

https://www.linode.com/docs/web-servers/nginx/slightly-more-advanced-configurations-for-nginx/#basic-nginx-caching