Hello,
I'm pretty new to nginx but I have an issue you guys might be able to help. I have an LXC container with 2 CPU and 512MB of ram running an nginx reverse proxy for websites and tcp load balancing (postgres).
The proxy runs fine for around 90 days which is the time it takes for the whole ram to be filled up. We don't serve a lot of queries (around 1 mb/s of traffic) so I feel like adding more ram to the container will just slow down the problem.
Here's a picture of the ram usage (the drop is the restart of the server):
[https://imgur.com/K4kbICW](https://imgur.com/K4kbICW)
[https://imgur.com/Cr5ahUB](https://imgur.com/Cr5ahUB)
Here are 2 of my config files, maybe you guys could enlighten me if any settings might cause this ?
TCP load balancing for postgres:
upstream prod_db {
zone prod_db 64k;
server prod-db-1:5432;
server prod-db-2:5432 backup;
}
server {
listen 8001;
proxy_pass prod_db;
proxy_timeout 4h;
proxy_connect_timeout 1s;
}
and here's a simple of a site config:
upstream prod_web_1 {
server prod-web-1;
server prod-web-2;
keepalive 32;
}
proxy_cache_path /var/cache/nginx_prod_web_1 levels=1:2 keys_zone=prod_web_1_cache:10m max_size=512m use_temp_path=off;
# HTTP to HTTPS
server {
listen 80;
server_name web.example.com;
return 301 https://$host$request\_uri;
}
server {
listen 443 ssl;
server_name web.example.com;
ssl_certificate /etc/ssl/private/web.example.com.pem;
ssl_certificate\_key /etc/ssl/private/web.example.com.key;
location / {
proxy_set_header Host $host;
proxy_set_header Connection "";
proxy_http_version 1.1;
proxy_buffers 256 16k;
proxy_buffer_size 16k;
proxy_cache_use_stale timeout;
proxy_cache prod_web_1_cache;
expires 365d;
add_header Cache-Control "public";
proxy_pass http://prod_web_1;
}
# Custom pages for error codes
error_page 403 /errors/403.html;
error_page 404 /errors/404.html;
error_page 500 /errors/500.html;
error_page 502 /errors/502.html;
error_page 503 /errors/503.html;
error_page 504 /errors/504.html;
location /errors/ {
alias /var/www/html/errors/;
}
}
I am betting that your stats reflect the disk cache in memory used for the `proxy_cache` storage. It’s possible that you aren’t actually running out of working memory here (you don’t mention whether the restart was forced due to a lockup or precautionary).
What does the output of `free -m` look like vs the graph? Do you see a lot of usage in the `buffer` or `cache` column(s)?
Also, make sure the `/var/cache/nginx_prod_web_1` path is not stored on a RAM disk. You may also try lowering the expires / TTL.
Try; sync echo 1 > /proc/sys/vm/drop\_caches
Linux doesn’t free memory just for the take of it, as freeing memory is expensive. The linux kernel will use free space and only clear what is needed when it is needed.