大网数据广告活动
服务器运维问答

Nginx: could not build map_hash, you should increase map_hash_bucket_size: 64

· 52CE 我爱测

I need to use redirect map with quite a lot rules (2k+ lines, file size is ~200K) I have the following settings in nginx: map $uri $new_uri { include /etc/nginx/conf.d/redirects.map; } server { listen 80 default_server; listen [:…

问题原文

原帖链接 · Putnik · CC BY-SA 3.0

I need to use redirect map with quite a lot rules (2k+ lines, file size is ~200K)

I have the following settings in nginx:

map $uri $new_uri {
        include /etc/nginx/conf.d/redirects.map;
}

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        # redirects
        if ($new_uri) {
                rewrite ^ $new_uri permanent;
        }

as described here and found here. The problem : configtest fails:

nginx: [emerg] could not build map_hash, you should increase map_hash_bucket_size: 64

I tried to increase map_hash_max_size and map_hash_bucket_size to quite crazy values:

map $uri $new_uri {
        map_hash_max_size 262144;
        map_hash_bucket_size 262144;
        include /etc/nginx/conf.d/redirects.map;
}

but still have the same error (ending exactly with '64'). I selected those values so they are bigger than the file size. I made sure I'm editing live config by adding "blabla" and see 'unknown directive'

So, how those values should be set? There's not much details in the official doc, unfortunately.

已采纳解答

原帖链接 · Alexey Ten · CC BY-SA 3.0

map_hash_max_size and map_hash_bucket_size must be in http context, i.e. outside of map directive.

map_hash_max_size 262144;
map_hash_bucket_size 262144;
map $uri $new_uri {
    include /etc/nginx/conf.d/redirects.map;
}

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-05-30)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。