Nginx 内存不足,无法加载新的虚拟主机?

Nginx 内存不足,无法加载新的虚拟主机?

我在 Debian 上运行了一个 nginx。Nginx 每 2 分钟会重新加载一次以获取新创建的虚拟主机。一段时间后,新的虚拟主机不再加载,但旧的虚拟主机仍由 nginx 提供服务

在我的 nginx 错误日志中,我可以发现多个错误。

2014/08/10 06:30:05 [alert] 27891#0: epoll_ctl(1, 4) failed (9: Bad file descriptor)
2014/08/10 06:30:05 [alert] 27892#0: close() channel failed (9: Bad file descriptor)
2014/08/10 06:30:05 [alert] 27893#0: close() channel failed (9: Bad file descriptor)
2014/08/10 06:30:19 [alert] 4806#0: worker process 27891 exited with fatal code 2 and can not be respawn
2014/08/10 06:30:19 [alert] 4806#0: sendmsg() failed (9: Bad file descriptor)
2014/08/10 06:30:05 [alert] 27894#0: close() channel failed (9: Bad file descriptor)
2014/08/10 06:30:20 [alert] 4806#0: sendmsg() failed (9: Bad file descriptor)
2014/08/10 06:30:20 [alert] 4806#0: sendmsg() failed (9: Bad file descriptor)
2014/08/10 06:30:20 [alert] 4806#0: sendmsg() failed (9: Bad file descriptor)
2014/08/10 06:30:20 [alert] 4806#0: sendmsg() failed (9: Bad file descriptor)

我过去曾尝试寻找解决方案,最终添加了

worker_rlimit_nofile 300000;

但看起来这并没有起到作用。

我感觉我的盒子在某个时候内存不足,但并不完全确定。

重新启动 nginx 解决了这个问题,但我担心过一段时间可能会再次遇到这个问题。

我看到的另一件奇怪的事情是,重新启动 nginx 后,交换就在我的统计数据中消失了。(见截图)。

nginx 重启后交换空间消失

如果你想看我的 nginx.conf,它在这里:

user www-data;
worker_processes  4;
worker_rlimit_nofile 300000;

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

events {
    worker_connections  2000;
    # multi_accept on;
}

http {
    include       /etc/nginx/mime.types;
    server_names_hash_max_size  812000;

    geoip_country  /etc/nginx/geoip/GeoIP.dat; # the country IP database
    geoip_city     /etc/nginx/geoip/GeoLiteCity.dat; # the city IP database

        log_format withhost '$host - $remote_addr - $remote_user [$time_local]  '
                    '"$request" $status $body_bytes_sent '
                    '"$http_referer" "$http_user_agent"';

#    access_log /var/log/nginx/access.log withhost;

#    set_real_ip_from   141.101.64.0/18;
#    set_real_ip_from   108.162.192.0/18;
#    set_real_ip_from   190.93.240.0/20;
#    set_real_ip_from   2400:cb00::/32;
#    set_real_ip_from   2606:4700::/32;
    set_real_ip_from   69.164.223.55;
    set_real_ip_from   212.123.14.6;
    set_real_ip_from   192.168.255.17;
    real_ip_header    X-Forwarded-For;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
    tcp_nodelay        on;

    server_tokens off;

    gzip  on;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";

    include /etc/nginx/conf.d/*.conf;
    include /nfs/vhosts/*;

    include /etc/nginx/sites-enabled/*;

}

希望有人能帮助我找出这个问题的原因并帮助我解决它。

问候!

相关内容