Nginx 一段时间后停止,没有记录任何可跟踪的日志

Nginx 一段时间后停止,没有记录任何可跟踪的日志

我有一台服务器(Ubuntu 20.04),它使用 Nginx 作为 Web 服务器。此外,它上面还有几个项目。问题是,有时 Nginx 会失败(停止)。如下所示:

在此处输入图片描述

我真的不知道它为什么会崩溃。我搜索了很多,并在服务器块(端口监听)中做了一些更改,但它有时仍然会停止。重要的是,当我systemctl restart nginx重新运行它时,它也能正常工作,但过了一会儿,它又失败了。

其中最后 10 行的结果为nginx error log

2023/03/17 06:54:46 [emerg] 88675#88675: bind() to 0.0.0.0:443 failed (98: Address already in use)
2023/03/17 06:54:46 [emerg] 88675#88675: bind() to 0.0.0.0:80 failed (98: Address already in use)
2023/03/17 06:54:46 [emerg] 88675#88675: bind() to [::]:80 failed (98: Address already in use)
2023/03/17 06:54:46 [emerg] 88675#88675: bind() to 0.0.0.0:443 failed (98: Address already in use)
2023/03/17 06:54:46 [emerg] 88675#88675: bind() to 0.0.0.0:80 failed (98: Address already in use)
2023/03/17 06:54:46 [emerg] 88675#88675: bind() to [::]:80 failed (98: Address already in use)
2023/03/17 06:54:46 [emerg] 88675#88675: bind() to 0.0.0.0:443 failed (98: Address already in use)
2023/03/17 06:54:46 [emerg] 88675#88675: still could not bind()
2023/03/17 06:54:48 [error] 88631#88631: MEMSTORE:19: my procslot not found! I don't know what to do!
nginx: worker process: /build/nginx-lUTckl/nginx-1.18.0/debian/modules/nchan/src/store/memory/memstore.c:1616: nchan_store_exit_worker: Assertion `0' failed.

以下是/etc/nginx/sites-enabled/default内容:

server {    
    server_name api5.arshiyaniha.com;
    root /var/www/html/api/public/ ;

    error_log /var/log/nginx/api-new-error.log ;
    access_log /var/log/nginx/api-new.log ;

    index index.php index.html index.htm index.nginx-debian.html ;

    if ($request_uri ~* "^(.*/)index\.php$") {
       return 301 $1;
    }

    location / {
       try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.1-fpm.sock;
        fastcgi_read_timeout 2000;
    }

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/api5.arshiyaniha.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/api5.arshiyaniha.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}


server {
        server_name arshiyanadmin.arshiyaniha.com;
        root /var/www/html/panel-front/build/ ;

        error_log /var/log/nginx/arshiyanadmin.log ;
        access_log /var/log/nginx/arshiyanadmin.log ;

        index index.html;

        location / {
           try_files $uri $uri/ /index.html?$query_string;
        }

    client_max_body_size 10M;

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/arshiyanadmin.arshiyaniha.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/arshiyanadmin.arshiyaniha.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server { 
     server_name api.arshiyaniha.com;
     location / {
          proxy_pass http://localhost:4020;
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection 'upgrade';
          proxy_set_header Host $host;
          proxy_cache_bypass $http_upgrade;
     }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/api.arshiyaniha.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/api.arshiyaniha.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server {
     server_name dashboardapi.arshiyaniha.com;
     location / {
          proxy_pass http://localhost:4021;
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection 'upgrade';
          proxy_set_header Host $host;
          proxy_cache_bypass $http_upgrade;
          proxy_connect_timeout 60s;
          proxy_read_timeout 5400s; 
          proxy_send_timeout 5400s;
    }

    listen 443 ssl; # managed by Certbot 
    ssl_certificate /etc/letsencrypt/live/dashboardapi.arshiyaniha.com/fullchain.pem; # managed by Certbot 
    ssl_certificate_key /etc/letsencrypt/live/dashboardapi.arshiyaniha.com/privkey.pem; # managed by Certbot 
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot 
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

server { 
     server_name files.arshiyaniha.com;
     location / {
          proxy_pass http://localhost:4022;
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection 'upgrade';
          proxy_set_header Host $host;
          proxy_cache_bypass $http_upgrade;
     }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/files.arshiyaniha.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/files.arshiyaniha.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

server {
    if ($host = api.arshiyaniha.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot
 
    server_name api.arshiyaniha.com;
    listen 80;
    return 404; # managed by Certbot
}

server {
    if ($host = files.arshiyaniha.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    server_name files.arshiyaniha.com;
    listen 80;
    return 404; # managed by Certbot

}

server {
    if ($host = dashboardapi.arshiyaniha.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    server_name dashboardapi.arshiyaniha.com;
    listen 80;
    return 404; # managed by Certbot
}

server {
    if ($host = arshiyanadmin.arshiyaniha.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot
   
    server_name arshiyanadmin.arshiyaniha.com;
    listen 80;
    return 404; # managed by Certbot
}


server {
    if ($host = api5.arshiyaniha.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    listen 80;
    listen [::]:80;    

    server_name api5.arshiyaniha.com;
    return 404; # managed by Certbot
}

知道具体问题是什么以及我该如何解决它吗?

答案1

这听起来像是一个 4 岁的孩子漏洞。虽然它已被标记为已解决。但它可能尚未被移植到您的操作系统中。

我知道这不是解决办法,但作为一种解决方法,你可以配置 systemd 在失败时自动重启 nginx

创建新目录,

mkdir /etc/systemd/system/nginx.service.d/

创建新文件

nano /etc/systemd/system/nginx.service.d/override.conf

粘贴以下内容

[Unit]
StartLimitIntervalSec=500
StartLimitBurst=5

[Service]
Restart=on-failure
RestartSec=5s

现在重新启动守护进程服务和 nginx。

尝试一下。

相关内容