Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

The nginx documentation on "Configuration file measurement units" at http://nginx.org/en/docs/syntax.html says:

Sizes can be specified in bytes, kilobytes (suffixes k and K) or megabytes (suffixes m and M)

This is unclear, because kilobyte is officially defined as 1000 bytes and megabyte is officially defined as 1000000 bytes, but often it is used to mean 1024 bytes and 1024 * 1024 bytes respectively. Exactly what size kilobyte is used in the nginx configuration files? When the documentation says the default is 1m is that 1000000 or 1048576?

share|improve this question
    
When software says "kilobyte", assume 1024 unless stated otherwise. When hardware says "kilobyte", assume 1000 unless stated otherwise. –  Shane Madden Oct 1 '13 at 22:49

1 Answer 1

up vote 4 down vote accepted

Looking at the source at http://hg.nginx.org/nginx/file/15056a29841a/src/core/ngx_parse.c (this is the version of ngx_parse.c in 1.5.6, but the function appears the same in the 0.3.53 version), it appears k or K represent 1024 bytes, that is, kibibytes (KiB) and m or M represents mebibytes (MiB), that is 1024 KiB.

ssize_t
ngx_parse_size(ngx_str_t *line)
{
    u_char     unit;
    size_t     len;
    ssize_t    size;
    ngx_int_t  scale;

    len = line->len;
    unit = line->data[len - 1];

    switch (unit) {
    case 'K':
    case 'k':
        len--;
        scale = 1024;
        break;

    case 'M':
    case 'm':
        len--;
        scale = 1024 * 1024;
        break;

    default:
        scale = 1;
    }

    size = ngx_atosz(line->data, len);
    if (size == NGX_ERROR) {
        return NGX_ERROR;
    }

    size *= scale;

    return size;
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.