hi,请教大家,由于公司需要,我们用nginx来cache网站的页面,根据页面自己身上设置cache-control max-age来cache的时长,cache尊源。
但是我们上线会,发现nginx内存持续升高直到接近系统的内存,发现它会自己降下来,按道理nginx不应该会这么耗内存的吧。查了下相关的资料发现论坛里面有说是lua module,ngx.var.XXX 引起的,也下载过systemstp 工具,由于自己是搞开发的,对系统内核这方面不是很了解,工具也不是很会使用。
希望大家能帮忙提出相关优化nginx的及系统内核的点。在此非常感激。
对外,如果用nginx proxy cache ,那nginx能承受的住吗? 例如:淘宝的双11,秒杀等活动。希望,有这方面的经验的朋友帮忙指点指点。感谢了!
以下是我的配置
系统:centos 6.3
内存:126G
磁盘:1.8T (raid0 7块磁盘)
网卡:万兆
系统里面有记下表示拿不定主意:
open_file_cache,开启gzip(时时压缩),keepalive_requests默认是100, 改大了,等等。
user nginx nginx;
worker_processes 32;
worker_rlimit_nofile 65535;
error_log logs/error.log error;
google_perftools_profiles /tmp/tcmalloc;
events {
use epoll;
worker_connections 65535;
}
http {
include mime.types;
default_type text/plain;
server_tokens off;
server_names_hash_bucket_size 128;
client_header_buffer_size 4k;
large_client_header_buffers 4 32k;
client_max_body_size 300m;
lua_package_path "/usr/local/nginx/conf/hash/?.lua;;";
lua_code_cache on;
#proxy_intercept_errors off;
log_format main '$time_iso8601 $request_uri $status'
' $bytes_sent $upstream_cache_status'
' $request_time'
' $upstream_response_time'
' $host'
' $remote_addr'
' $server_addr'
' $upstream_addr'
' $http_referer'
' $http_user_agent'
' $http_X_Forwarded_For'
' 1'
' $cachezone';
access_log logs/access.log main;
sendfile on;
tcp_nopush on;
keepalive_timeout 15;
send_timeout 2;
keepalive_requests 1000000;
open_file_cache max=65535 inactive=20s;
open_file_cache_min_uses 1;
open_file_cache_valid 30s;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_vary on;
gzip_types text/plain application/x-_javascript_ text/css application/xml;
client_body_timeout 10;
client_body_buffer_size 512k;
proxy_connect_timeout 30;
proxy_read_timeout 30;
proxy_send_timeout 30;
proxy_buffer_size 64k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
proxy_temp_path /tmp;
proxy_cache_path /home/disk1/tmp levels=1:2 keys_zone=cache1:2048m inactive=7d max_size=245g;
proxy_cache_path /home/disk2/tmp levels=1:2 keys_zone=cache2:2048m inactive=7d max_size=245g;
proxy_cache_path /home/disk3/tmp levels=1:2 keys_zone=cache3:2048m inactive=7d max_size=245g;
proxy_cache_path /home/disk4/tmp levels=1:2 keys_zone=cache4:2048m inactive=7d max_size=245g;
proxy_cache_path /home/disk5/tmp levels=1:2 keys_zone=cache5:2048m inactive=7d max_size=245g;
proxy_cache_path /home/disk6/tmp levels=1:2 keys_zone=cache6:2048m inactive=7d max_size=245g;
proxy_cache_path /home/disk7/tmp levels=1:2 keys_zone=cache7:2048m inactive=7d max_size=245g;
limit_conn_zone $status zone=addr:10m;
##### m
upstream test {
server 192.168.100.10 weight=30 max_fails=2 fail_timeout=10s;
}
#resolver 8.8.8.8;
server {
listen 192.168.100.2:80;
server_name ~(?<domain>.+\.test)\.com$;
location / {
set_by_lua_file $cachezone /usr/local/nginx/conf/hash/parser.lua; #consistent_hash ngx.req.get_headers()["Host"]..ngx.var.uri
if ( $cachezone = "cache1" ) {
rewrite ^ /cache1;
}
if ( $cachezone = "cache2" ) {
rewrite ^ /cache2;
}
if ( $cachezone = "cache3" ) {
rewrite ^ /cache3;
}
if ( $cachezone = "cache4" ) {
rewrite ^ /cache4;
}
if ( $cachezone = "cache5" ) {
rewrite ^ /cache5;
}
if ( $cachezone = "cache6" ) {
rewrite ^ /cache6;
}
if ( $cachezone = "cache7" ) {
rewrite ^ /cache7;
}
}
location /cache1 {
internal;
proxy_cache cache1;
limit_conn addr 2500;
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_cache_valid 200 304 10m;
proxy_cache_valid 301 302 1m;
proxy_cache_key $host$request_uri;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://$domain$request_uri;
proxy_errors_log_upstream http_500 http_404;
proxy_cache_lock on;
proxy_cache_lock_timeout 32;
proxy_cache_bypass $cookie_nocache $arg_nocache;
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
proxy_no_cache $sent_http_x_nomirror;
#proxy_intercept_errors on;
}
#cache2,cache3,cache4,cache5……
location ~* \/ga.aspx\?*$ {
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://$domain;
}
location ~* \/error/50x.aspx$ {
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://$domain;
}
error_page 404 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
sysguard on;
sysguard_load load=32 action="">
sysguard_mem swapratio=20% action="">
location /loadlimit {
return 503;
}
location /swaplimit {
return 503;
}
location /nginx-status {
stub_status on;
allow 192.168.101.0/24;
deny all;
access_log off;
}
}
}