3
回答
Tengine反向代理 响应慢,但其实后台程序已经快速处理完成的问题
终于搞明白,存储TCO原来是这样算的>>>   
从nginx日志中发现,响应时间有时候会长,可是后端处理时间却很小(如:响应时间是5秒,处理时间却是0.08),在后端web系统日志上查看这条请求 记录响应时间却很小(不到1秒)。

不知道为什么会出现这种情况,(服务器性能一切正常)

哪位遇到了这样的情况。

Tengine配置如下:

---------------------------------------------------------------------------------------

#user  nobody;
worker_processes  auto;
#worker_rlimit_nofile 100000;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

pid        logs/nginx.pid;

events {
use epoll;
# multi_accept on;
worker_connections  8192;
}


# load modules compiled as Dynamic Shared Object (DSO)
dso {
#    load ngx_http_fastcgi_module.so;
#    load ngx_http_rewrite_module.so;
     load ngx_http_cache_purge_module.so;
}

http {
server_tokens off;

add_header  X-UA-Compatible 'IE=Edge,chrome=1'; # 这里是自定义头
#include blockip.conf;

include       mime.types;
default_type  application/octet-stream;

log_format  access  '$remote_addr - $remote_user [$time_local] "$host$uri" '
     '$status $body_bytes_sent "$http_referer" '
     '"$http_user_agent" "$http_x_forwarded_for" $request_time';

#access_log  logs/access.log  access;

sendfile        on;
#tcp_nopush     on;
client_max_body_size 10m; 
client_body_timeout 300;

#keepalive_timeout  0;
keepalive_timeout  65;

client_header_buffer_size 32k;#默认是4k
large_client_header_buffers 4 32k;

gzip on; 
gzip_min_length  1k; 
gzip_buffers     4 16k; 
gzip_http_version 1.0; 
gzip_comp_level 2; 
gzip_types       text/plain application/x-javascript text/css application/xml; 
gzip_vary on;

upstream myligerproject {  
#这里指定多个源服务器,ip:端口,80端口的话可写可不写
server localhost:9101 fail_timeout=300s;
server localhost:9102 fail_timeout=300s;

#check interval=3000 rise=2 fall=5 timeout=1000 type=http;
#check_keepalive_requests 100;
        #check_http_send "HEAD / HTTP/1.1\r\nConnection: keep-alive\r\n\r\n";
        #check_http_send "HEAD / HTTP/1.0\r\n\r\n";
        #check_http_expect_alive http_2xx http_3xx;

ip_hash;
}

#注:proxy_temp_path和proxy_cache_path指定的路径必须在同一分区
proxy_temp_path   /export/home/process/tengine/proxy_temp_dir;
#设置Web缓存区名称为cache_one,内存缓存空间大小为200MB,1天没有被访问的内容自动清除,硬盘缓存空间大小为30GB。
proxy_cache_path /export/home/process/tengine/proxy_cache_dir levels=1:2 keys_zone=cache_one:200m inactive=1d max_size=30g;

# forbid ip visit
server {
listen 80 default;
return 500;
}

server {
listen       80;
server_name  ***.com;
#index index;
}

server {
listen       80 ;
server_name  www.***.com;

#location ~ .*\.(gif|jpg|jpeg|png|ico|cur|rar|css|js|zip|flv|swf|doc|ppt)$ {
location ~ /public/.*\.(xls|gif|jpg|jpeg|png|ico|cur|rar|zip|flv|swf|doc|ppt|js|css)$ {
root /export/home/process/webroot/;
access_log off;
expires 7d;
}

location ~ ^/favicon.ico$ {
root /export/home/process/images/;
access_log off;
expires 7d;
}

location ~ /detail_.*\.html$ {
proxy_cache cache_one;
#对不同的HTTP状态码设置不同的缓存时间
proxy_cache_valid  200 304 302 24h;
#以域名、URI、参数组合成Web缓存的Key值,Nginx根据Key值哈希,存储缓存内容到二级缓存目录内
proxy_cache_key $host$uri$is_args$args;

proxy_pass         http://myligerproject;
proxy_set_header   Host             $host;
proxy_set_header   X-Real-IP         $remote_addr;
proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;

proxy_connect_timeout       600;
proxy_read_timeout          600;
proxy_send_timeout          600;


#expires 1d;
}

#用于清除缓存,假设一个URL为http://192.168.8.42/test.txt,通过访问http://192.168.8.42/purge/test.txt就可以清除该URL的缓存。
location ~ /purge(/.*) {
#设置只允许指定的IP或IP段才可以清除URL缓存。
allow all;
#allow 127.0.0.1;
#allow 192.168.0.0/16;
#deny all;
#proxy_cache_purge cache_one   $host$1$is_args$args;


location / {
proxy_pass         http://myligerproject/;
proxy_set_header   Host             $host;
proxy_set_header   X-Real-IP         $remote_addr;
proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;

proxy_connect_timeout       600;
proxy_read_timeout          600;
proxy_send_timeout          600;
}

location ~ ^/NginxStatus/ {
stub_status on; #Nginx 状态监控配置
access_log off;
}

        location /status {
            check_status;

            access_log   off;
        #    allow SOME.IP.ADD.RESS;
        #    deny all;
        }

error_page  404              /404.html;

# redirect server error pages to the static page /50x.html
#
#error_page   500 502 503 504  /Application/detail_error;
error_page   500 502 503 504  /50x.html;
location = /50x.html {
root   html;

}

server {
listen       80;
server_name  static.***.com;

#access_log  logs/host.access.log  main;

        large_client_header_buffers 4 16k;
        client_max_body_size 300m;
        client_body_buffer_size 128k;
        proxy_connect_timeout 600;
        proxy_read_timeout 600;
        proxy_send_timeout 600;

proxy_buffer_size 64k;#设置代理服务器(nginx)保存用户头信息的缓冲区大小
proxy_buffers   4 32k;#proxy_buffers缓冲区,网页平均在32k以下的话,这样设置
proxy_busy_buffers_size 64k;#高负荷下缓冲大小(proxy_buffers*2)
proxy_temp_file_write_size 64k;#设定缓存文件夹大小,大于这个值,将从upstream服务器传递请求,而不缓冲到磁盘

location ~ /sell/.*\.(gif|jpg|jpeg|png|ico|JPG|GIF|PNG|JPEG)$ {
root /export/home/data/photo/;
access_log off;
expires 7d;
}

location ~ /buy/.*\.(gif|jpg|jpeg|png|ico|JPG|GIF|PNG|JPEG)$ {
root /export/home/data/photo/;
access_log off;
expires 7d;
}

location ~ /public/.*\.(xls|gif|jpg|jpeg|png|ico|cur|rar|zip|flv|swf|doc|ppt|js|css)$ {
root /export/home/process/img/;
access_log off;
expires 7d;
}
}
}

举报
javadeveloper
发帖于3年前 3回/764阅
顶部