Salt: Increase nginx server_names_hash_bucket_size

Problem:

You use saltstack to automatically deploy configuration to your servers. After installing nginx with the default config, you need to increase the server_names_hash_bucket_size because it won’t startup otherwise.

Solution

The most obvious solution is to replace the entire config file by a config crafted by you. This might have some disadvantages regarding nginx version compatibility, however, so it might be useful to replace on the single variable.

In order to do this, use a SLS directive like this:

sed -i 's/# server_names_hash_bucket_size 64;/server_names_hash_bucket_size 96;/g' /etc/nginx/nginx.conf

This command runs after the nginx package has been installed and replaces the Debian default value by 96. Already modified values are not replaced. Depending on the exact system/distribution in use, you might have to use a regular expression or another default value.