# 根据你服务器的cpu核数来确定此值
worker_processes 4; error_log logs/error.log crit;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; worker_rlimit_nofile 65535; # events事件主要用来确定Nginx使用哪种算法
events {
use epoll;
worker_connections 65535;
} 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"'; # 由于Nginx用于代理Tomcat,所以记录访问日志的事情交给Tomcat来做好了,注释掉
#access_log logs/access.log main; sendfile on;
tcp_nopush on;
tcp_nodelay on; #keepalive_timeout 0;
keepalive_timeout 65; server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 3m;
client_body_buffer_size 512k; # 代理的相关参数设置
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; # 启用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; # 配置需要代理的tomcat
upstream tomcat_proxy{
ip_hash;
session_sticky;
server 192.168.1.114:8080;
} # 虚拟主机:www.abc.com
server {
listen 80;
server_name www.abc.com;
index index.html index.htm index.jsp;
root /home/webapp/www/app1; if (-d $request_filename){
rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
} # 动态页面,交给tomcat处理
location ~ \.(jsp|jspx|do|action)?$ {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://tomcat_proxy;
} location /training/ {
proxy_pass http://tomcat_proxy;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#sub_filter /training/ /;
} # 用户浏览器端的缓存设置
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
expires 10d;
} location ~ .*\.(js|css)?$ {
expires 1h;
} access_log off;
#charset koi8-r;
#access_log logs/host.access.log main;
}
}
设置确认没有问题,保存退出,可重启: service nginx restart