1. 在目录/etc/nginx/conf.d 下新建一个文件 tomcatserver.conf (tomcatserver可以修改为其它的名字),在文件中添加如下内容:
2. 在目录 /etc/nginx/ 下修改文件 nginx.conf,我系统的配置文件如下,大家可对照修改:
#使用的用户和用户组
user cwowhappy cwowhappy;
#指定工作衍生进程数
worker_processes 4;
#指定错误日志存放的路径,错误日志记录级别可选为:[debug | info | notice | warn | error | crit]
error_log /var/log/nginx/error.log;
#error_log /var/log/nginx/error.log notice;
#error_log /var/log/nginx/error.log info;
#指定进程id存放的文件
pid /var/run/nginx.pid;
events {
#使用的网络I/O模型(
linux推荐使用epoll模型)
use epoll;
#允许的连接数
worker_connections 1024;
}
http {
include /etc/nginx/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 /var/log/nginx/access.log main;
#add by cwowhappy 2014-04-21 configure Ngimx+Tomcat start
#编码格式
charset utf-8;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
client_body_buffer_size 512k;
large_client_header_buffers 4 32k;
client_max_body_size 300m;
#add by cwowhappy 2014-04-21 end
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
tcp_nodelay on;
#add by cwowhappy 2014-04-21 configure Nginx+Tomcat start
proxy_connect_timeout 5;
proxy_read_timeout 60;
proxy_send_timeout 5;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
#add by cwowhappy 2014-04-21 configure Nginx+Tomcat end
#压缩输出配置
gzip
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/x-
javascript text/css application/xml
gzip_vary on;
# Load config files from the /etc/nginx/conf.d directory
# The default server is in conf.d/default.conf
include /etc/nginx/conf.d/tomcatserver.conf;
}
3. 修改tomcat的配置文件server.xml(此文件位于tomcat安装目录下的conf目录下),修改内容如下: