本文轉載自: https://www.93bok.com
前言
今天改了nginx的一個配置參數,所以就reload了一下,我去,竟然報錯了Cannot allocate memory起不來,日志報錯如下:
- 報錯如下圖
[alert] 21470#0: mmap(MAP_ANON|MAP_SHARED, 536870912) failed (12: Cannot allocate memory)
解決
1. 查看一下內存還剩多少
free -m
total used free shared buff/cache available
Mem: 992 427 77 81 487 314
Swap: 0 0 0
2. 修改配置文件
vim /etc/nginx/nginx.conf
fastcgi_cache_path /data/www/wordpress/fastcgi/ngx_fcgi_cache levels=2:2 keys_zone=ngx_fcgi_cache:500m inactive=30s max_size=5g;
- 把上邊的500m改成free內存的數量即可,但是也不要一點不剩,這里我改成了50m
3. 修改完配置文件之后測試一下配置文件是否通過檢測
nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful