nginx: [alert] mmap() failed (22: Invalid argument)

Posted December 1, 2020 1.6k views
[root@asraulnew ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: [alert] mmap(MAP_ANON|MAP_SHARED, 16777216000) failed (12: Cannot allocate memory)
nginx: [alert] munmap(FFFFFFFFFFFFFFFF, 16777216000) failed (22: Invalid argument)
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed

Anyone, please help me to solve this error.

edited by bobbyiliev

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Hi there,

It looks like you’ve set too high values for your Nginx service. You need to lower down the values or add more RAM to your server because at the moment Nginx is trying to use more memory than you actually have on your server.

Feel free to share your Nginx configuration file here so that I could advise you on which values you might need to change.


  • worker_processes  2;
    user apache apache;
    worker_rlimit_nofile 10240;
    error_log  logs/error.log crit;
    #error_log  logs/error.log  notice;
    #error_log  logs/error.log  info;
    #error_log  logs/error.log  debug;
    events {
        worker_connections  10240;
        multi_accept on;
    http {
        include       mime.types;
        #default_type  application/octet-stream;
        default_type  video/mp4;
        log_format  xfstube '$arg_id|$arg_usr|$arg_dmode|$arg_ip|$arg_flags|$body_bytes_sent|$status';
        log_format  xvshls  '$xhash|$bytes_sent';
        #error_log  logs/error.log  error;
        limit_conn_log_level warn;
        mp4_buffer_size 1M;
        mp4_max_buffer_size 10M;
        # file handle caching / aio
        open_file_cache          max=200000 inactive=3m;
        open_file_cache_valid    2m;
        open_file_cache_min_uses 2;
        open_file_cache_errors   on;
        aio on;
        #directio 8m;
        #directio_alignment 4096;
        access_log off;
        #sendfile        on;
        tcp_nopush on;
        reset_timedout_connection on;
        #keepalive_timeout  0;
        keepalive_timeout  15;
        client_body_timeout 10;
        #send_timeout 3;
        keepalive_requests 1000;
        limit_conn_zone $binary_remote_addr zone=addr:20m;
        upload_progress proxied 2m;
        include sites/*.conf;
    #include mod_rtmp.conf;
    #include mod_streaming.conf;
    • Hello,

      It is not fully clear which value is causing the error as this might be due to some of the includes.

      What I would suggest is to try with a larger Droplet, or try to increase the shared memory as suggested here:

      • Place an entry in /etc/sysctl.conf like:

      Then persist the changes with:

      • sudo sysctl -p