开发者社区> 问答> 正文

Nginx+tomcat处理速度问题

一个内部的系统,javaEE实现,tomcat6.0,服务器是双核 4G内存,大概350用户
设置的是tomcat最大内存768M。
用了nginx-1.1.10反向代理,发现速度反而被拖累了,没有直接用tomcat快(非常明显),贴出我的配置,大家帮我看看问题出在什么地方:

 #user nobody;
worker_processes 2;

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

#pid logs/nginx.pid;

events {
worker_connections 1024;
}

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

#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';

#access_log logs/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

gzip on;

#cache
proxy_temp_path D:/nginx-1.1.10/temp/my; 
proxy_cache_path D:/nginx-1.1.10/temp/my keys_zone=mycache:200m inactive=1d max_size=1g; 
upstream backend { 
server localhost:8282 weight=2; 
#server localhost:8283;
ip_hash; 
#add for session
#jvm_route $cookie_JSESSIONID|sessionid reverse;
}
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;

location / {
root html;
index index.html index.htm;
proxy_pass http://backend;
#newly add
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; 
client_max_body_size 10m;
client_body_buffer_size 256k;
proxy_connect_timeout 15;
proxy_send_timeout 15;
proxy_read_timeout 15; 
}
location ~* \.(gif|jpg|jpeg|png|bmp|swf|js|css)$ 
{ 
proxy_cache mycache; 
proxy_cache_methods GET HEAD POST; 
proxy_cache_min_uses 1; 
proxy_cache_valid 200 302 10m; 
proxy_cache_valid 404 1m; 
proxy_cache_valid any 1m; 
proxy_cache_key "$host:$server_port$uri$is_args$args"; 

proxy_redirect off; 
proxy_pass http://backend;
} 
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;

# location / {
# root html;
# index index.html index.htm;
# }
#}

# HTTPS server
#
#server {
# listen 443;
# server_name localhost;

# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;

# ssl_session_timeout 5m;

# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;

# location / {
# root html;
# index index.html index.htm;
# }
#}

}

展开
收起
落地花开啦 2016-03-26 11:24:38 3087 0
1 条回答
写回答
取消 提交回答
  • 喜欢技术,喜欢努力的人

    速度肯定会慢啊,多了一层代理时间啊!!!
    前端加nginx/apache目标不是加快单个请求的速度,而是负载均衡加大并发吞吐量(接入loadbalance到多机),你如果稍微深入做大并发应用就不会得出这样的结论
    当然,nginx用linux版本是推荐的,但是这应该不是问题所在

    2019-07-17 19:15:53
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
《Nginx 代理系统常用手册》 立即下载
CentOS Nginx PHP JAVA 多语言镜像使用手 立即下载
CentOS Nginx PHP JAVA多语言镜像使用手册 立即下载