Nginx与tomcat反向代理

nginx反向代理tomcat配置

user用户名;

worker_processescpu的核数*2;

error_log错误日志crit;

pidnginx_home/nginx.pid

worker_rlimit_nofile描述文件(与linux有关)65535

events

{

useepoll;

worker_connections65535;

}

http

{

includemime.types;

default_typeapplication/octet-stream;

server_names_hash_bucket_size128;

client_header_buffer_size32k;

large_client_header_buffers432k;

client_max_body_size300m;

sendfileon;

tcp_nopushon;

keepalive_timeout60;

tcp_nodelayon;

client_body_buffer_size512k;

proxy_connect_timeout5;

proxy_read_timeout60;

proxy_send_timeout5;

proxy_buffer_size16k;

proxy_busy_buffers_size128k;

proxy_temp_file_write_size128k;

gzipon;

gzip_min_length1k;

gzip_http_version1.1;

gzip_buffers416k;

gzip_comp_level2;

gzip_typestext/plainapplication/x-javascripttext/cssapplication/xml

gzip_varyon;

upstreamtomcat_server

{

ip_hash;-->负载均衡时,保证同一用户的所有请求都指向同一台服务器。因为这台服务器中保存了session,application等等相关信息

serverip:port;

}

server

{

listen80;

server_namewww.domain.com;

indexindex.htmlindex.jsp

root/usr/local/data/

location~\.(jsp|jspx|do)?$

{

proxy_next_upstreamhttp_502http_504errortimeoutinvalid_header;

proxy_set_headerHost$host;

proxy_set_headerX-Forwarded-For$remote_addr;

proxy_passhttp://tomcat_server;

}

location~.*\.(gif|jpg|jpeg|png|bmp|swf)$

{

expires30d;

}

location~.*\.(js|css)?$

{

expires1h;

}

access_logoff;

}

}

相关推荐