Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Nginx: What is server_names_hash_bucket_size?

Background

While I'm learning how to use Nginx, I was instructed to update the server_names_hash_bucket_size (/etc/nginx/nginx.conf) value from 32 to 64, but I don't understand why should I increase the value to 64.

References

References that have been read so far:

Key takeaways

  • The default value of server_names_hash_bucket_size depends on the size of the processor’s cache line
  • If a large number of server names are defined, or unusually long server names are defined, tuning the server_names_hash_max_size and server_names_hash_bucket_size directives at the http level may become necessary.
  • If the default value of server_names_hash_bucket_size used at the server is not enough, means nginx complained with could not build the server_names_hash, you should increase server_names_hash_bucket_size: 32, the directive value should be increased to the next power of two (e.g. in this case to 64).
  • If a large number of server names are defined, and nginx complained with the following error could not build the server_names_hash, you should increase either server_names_hash_max_size: 512 or server_names_hash_bucket_size: 32. try to set server_names_hash_max_size to a number close to the number of server names. Only if this does not help, or if nginx’s start time is unacceptably long, try to increase server_names_hash_bucket_size.
  • The hash bucket size parameter is aligned to the size that is a multiple of the processor’s cache line size
@DougBeney

This comment has been minimized.

Copy link

@DougBeney DougBeney commented May 16, 2018

Thanks for creating this!

@mattbontrager

This comment has been minimized.

Copy link

@mattbontrager mattbontrager commented May 24, 2018

Hear Hear!

@hemantgoyal

This comment has been minimized.

Copy link

@hemantgoyal hemantgoyal commented Sep 3, 2018

Thanks for this. Can you also please the difference between the max and the bucket size ? It still confuses me.

@Raymond26

This comment has been minimized.

Copy link

@Raymond26 Raymond26 commented Nov 8, 2018

Thanks for this!

@kowalski-relent

This comment has been minimized.

Copy link

@kowalski-relent kowalski-relent commented May 5, 2020

Thanks for this!

@sto1t

This comment has been minimized.

Copy link

@sto1t sto1t commented Mar 6, 2021

√ Still useful. Thanks!

@inoas

This comment has been minimized.

Copy link

@inoas inoas commented May 6, 2021

Well I raised both values to powers of 2 in steps till 512 and it did nothing.
Shortening very long local development domains worked.

ROLE-dashboard-COMPANY-TLD-docker-FRAMEWORK.local + 4 letters port => to something shorter fixed it for me.

@Meekohi

This comment has been minimized.

Copy link

@Meekohi Meekohi commented May 7, 2021

Kind of odd nginx can't just resize this on the fly. Updating from 32 to 256 worked for me.

@CiderAndWhisky

This comment has been minimized.

Copy link

@CiderAndWhisky CiderAndWhisky commented Aug 30, 2021

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment