解决错误:nginx: [alert] mmap(MAP_ANON|MAP_SHARED, 104857600) failed (12: Cannot allocate memory)

技术运维CentOSNginx 2514

今天发现一个站点的ssl证书没有被自动续期,查看了一下问题,发现是certbot在执行renew命令的时候会先检查nginx的语法配置,因为nginx有问题的时候会自行退出。

nginx -t 检测语法会出现下面错误:

nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: [alert] mmap(MAP_ANON|MAP_SHARED, 104857600) failed (12: Cannot allocate memory)
nginx: configuration file /etc/nginx/nginx.conf test failed

解决方法

使用命令检查剩余缓存,如果不出意外的话你看到的结果应该是非常小的

echo $((`cat /proc/sys/kernel/shmmax` / 1024 / 1024))Mb

接下来需要修改一个重要的参数: proxy_cache_path ,该参数位于nginx的conf文件中,以笔者的配置为例位于/etc/nginx/site-available/site.conf中,完整的参数规则如下:

proxy_cache_path /usr/nginx/cache levels=1:2 keys_zone=cacheZone:200m inactive=1d max_size=2g;

只需要修改这里的 cacheZone: 后面的200m,将它修改小一点即可,最后检测一下语法

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

已经一切正常了,最后用 nginx -s reload 重启一下即可。

Post Comment