Fixing Nginx's 'could not build optimal types_hash' Warning

beginner Nginx2026-06-12| Commonly seen on Ubuntu, Debian, CentOS, or RHEL servers running Nginx 1.10+ when handling extensive MIME type lists or complex site configurations.

Error Message

nginx: [warn] could not build optimal types_hash, you should increase either types_hash_max_size: 1024 or types_hash_bucket_size: 64; ignoring types_hash_bucket_size
#nginx#linux-administration#web-server#performance-tuning#devops

The WarningYou probably noticed this message after running nginx -t or trying to reload your service. It looks like this:

nginx: [warn] could not build optimal types_hash, you should increase either types_hash_max_size: 1024 or types_hash_bucket_size: 64; ignoring types_hash_bucket_size

While this won't crash your server, it means Nginx is using a sub-optimal lookup method. This can lead to a slight performance hit when serving files.

Why Is Nginx Complaining?Nginx uses hash tables to quickly map file extensions (like .php or .png) to their respective MIME types. These tables need to be small enough to fit in your CPU's cache but large enough to avoid collisions.

Standard Nginx installations handle about 100-150 MIME types by default. However, modern web apps often add dozens of custom types for fonts, specialized video formats, or manifest files. When your mime.types file grows too large, the default memory buckets overflow. Nginx then warns you that it can't find an 'optimal' way to organize these entries with the current memory limits.

How to Fix ItTo stop the warning, you need to give Nginx more breathing room in its configuration. We'll do this by doubling the suggested values.

1. Open your main configurationMost setups store the primary config file at /etc/nginx/nginx.conf. Open it with sudo privileges:

sudo nano /etc/nginx/nginx.conf

2. Adjust the http blockFind the http { ... } section. You are looking for two specific directives: types_hash_max_size and types_hash_bucket_size. If they aren't there, you'll need to add them manually.

Don't just use the numbers Nginx suggested in the error. Instead, double them to ensure you don't have to revisit this fix next week. If the error suggested 1024 and 64, use these values:

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    # Increase hash table sizes for better performance
    types_hash_max_size 2048;
    types_hash_bucket_size 128;

    # ... existing config
}

3. Save and ExitIf you're using Nano, press Ctrl + O and then Enter to save. Hit Ctrl + X to get back to your terminal.

Confirm the ChangesNever restart Nginx without testing the syntax first. One small typo can take your entire site offline.

sudo nginx -t

If everything is correct, the output will look like this:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Now, reload the service to apply the new settings:

sudo systemctl reload nginx

Deep Dive: What do these parameters do?- types_hash_max_size: This controls the total size of the hash table. Think of it as the total number of slots available for your MIME types.- types_hash_bucket_size: This represents the size of each individual slot (bucket). It should be a power of two (32, 64, 128) that matches your CPU's cache line size. If you have very long file extensions, Nginx needs larger buckets to store them.## Pro Tips for MaintenanceThis warning is usually a 'set it and forget it' fix. However, if you manage a fleet of servers, consistency is key. I often see configurations get corrupted during manual edits or automated deployments.

To ensure your mime.types or nginx.conf hasn't been accidentally altered, I recommend generating a checksum. Tools like the Hash Generator at ToolCraft are great for this. You can quickly generate an MD5 or SHA-256 hash of your config file in the browser. It's a simple way to verify that every server in your cluster is running the exact same configuration without uploading sensitive data to a third-party server. Still seeing the warning? Don't panic. Some massive configurations require even larger values. You can safely double the numbers again to 4096 and 256. Modern servers have plenty of RAM, and the memory impact here is measured in kilobytes, not megabytes.

Related Error Notes