【问题标题】:How to configure Nginx in docker and set server_names_hash_bucket_size如何在 docker 中配置 Nginx 并设置 server_names_hash_bucket_size
【发布时间】:2020-10-17 14:58:10
【问题描述】:

我在我的 nginx default.conf 中添加了一个 server_name server_name very.very.long.domain.name.used.in.this.example.org; 并出现此错误

nginx: [emerg] could not build server_names_hash, you should increase server_names_hash_bucket_size: 64

我阅读了 nginx 文档,我说我必须将它添加到我的 http 上下文中

http {
    . . .
    server_names_hash_bucket_size 64;
    . . .
}

我在 Nginx 目录下创建了一个 nginx.conf 并将其复制到 /etc/nginx/nginx.conf 中

nginx.conf

worker_processes  1;

events {
    worker_connections  4096;
}

http {
    server_names_hash_bucket_size 64;
    server_names_hash_max_size 512;

}

Dockerfile

FROM nginx
COPY ./default.conf /etc/nginx/conf.d/default.conf
COPY ./nginx.conf /etc/nginx/nginx.conf

但是现在 nginx 不服务默认端口 80

server {
    listen 80;
    server_name very.very.long.domain.name.used.in.this.example.org;;
    
    location / {
        proxy_pass http://admin;
    }

} 

【问题讨论】:

    标签: docker nginx nginx-config


    【解决方案1】:

    将此添加到 Dockerfile 将使用 sed 将值更改为 64:

    RUN sed -i 's/.*server_names_hash_bucket_size.*/\t server_names_hash_bucket_size 64;/' /etc/nginx/nginx.conf
    

    在开始nginx之前添加这一行。

    说明

    默认的nginx.conf已经注释掉了这一行,但是显示的默认值server_names_hash_bucket_size

    ...
        # server_names_hash_bucket_size 32;
    ...
    

    sed 命令将用未注释的行替换此行,该行将值设置为64(如果需要,设置更高):

    ...
        server_names_hash_bucket_size 64;
    ...
    

    这对你来说可能为时已晚@ArthurDecker,但我希望它可以帮助其他拥有这个的人?

    【讨论】:

      猜你喜欢
      • 2021-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-29
      • 2017-03-19
      • 2021-05-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多