nginx+tomcat的安装配置
时间:2010-09-15 来源:thatwo
Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP代理服务器。已经因为它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而被人们广泛使用了。
大多数人选择它主要考虑到的是它的高并发和负载均衡。
一、安装Nginx
1. tar zxvf nginx-0.7.44.tar.gz
2、编译安装nginx
cd nginx-0.7.44
./configure --with-http_stub_status_module --with-http_ssl_module --prefix=/usr/local/nginx
执行后,可能会提示 ./configure: error: the HTTP rewrite module requires the PCRE library.这个错误,是缺少pcre 包,可用yum install pcre pcre-devlel来解决
3、make && make install
4、nginx安装成功后的安装目录为/usr/local/nginx
5.编辑配置文件nginx.conf
#user www www;
worker_processes 8; #启动进程数,可根据机器核数来修改
error_log /usr/local/nginx/logs/nginx_error.log crit; #全局错误日志及PID文件
pid /usr/local/nginx/nginx.pid;
worker_rlimit_nofile 65535;
events
{
use epoll;
worker_connections 65535; #工作模式及连接数上限
}
http #设定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; #定义的日志格式和存放路径
#General Options
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_body_buffer_size 8m; #256k
server_tokens off;
ignore_invalid_headers on;
recursive_error_pages on;
server_name_in_redirect off;
sendfile on;
#timeouts
keepalive_timeout 60;
#client_body_timeout 3m;
#client_header_timeout 3m;
#send_timeout 3m;
#TCP Options
tcp_nopush on;
tcp_nodelay on;
#size limits
client_max_body_size 50m;
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 xxx.com {
ip_hash;
server x.x.x.x:8080 max_fails=0 weight=1;
server x.x.x.x:8080 max_fails=0 weight=1; #8080为tomcat端口
}
server {
listen 80 default;
rewrite ^(.*)