此篇就不矫情了。直接上个配置吧。之后如有更新,继续修补linux
user nginx;
worker_processes 10;
error_log logs/error.log; error_log logs/error.log notice; error_log logs/error.log info;
pid /var/run/nginx.pid;
events { # epoll是多路复用IO(I/O Multiplexing)中的一种方式 支持linux2.6以上内核 use epoll; # 单个后台worker process进程最大并发链接数 worker_connections 1024; # 优化同一时刻只有一个请求而避免多个睡眠进程被唤醒的设置,on为防止被同时唤醒,默认为off,所以nginx刚安装完之后要进行适当的优化。 accept_mutex on; # 打开同时接受多个新网络链接请求的功能。 multi_accept on; }
http { # 隐藏nginx版本号 server_tokens off; # 文件扩展名与文件类型映射表 include mime.types; # 默认文件类型 default_type application/octet-stream; # 设置日志格式 access_log /var/log/nginx/access.log; # 请求体最大容量 client_max_body_size 500M; # 开启高效文件传输模式 sendfile on; # 长链接超时时间 单位秒 keepalive_timeout 65; # 开启gzip压缩 gzip on; # 设定请求缓冲 client_header_buffer_size 1k; large_client_header_buffers 4 4k; # 引入外部配置文件 include /usr/local/nginx/conf/conf.d/*.conf; # FastCGI相关参数是为了改善网站的性能:减小资源占用,提升访问速度。 fastcgi_connect_timeout 900; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 128k; fastcgi_buffers 2 256k; fastcgi_busy_buffers_size 256k; fastcgi_temp_file_write_size 256k; }
upstream tomcat-servers {
# weight表明权重的意思,当前配置也是一个代理tomcat集群的配置,当前使用的方式是权重方式,除此以外还有轮询的方式还有基于ip分配等多种方式。
server 192.168.1.11:8080 weight 1;
server 192.168.1.12:8080 weight 6;
}nginx
server { # 端口监听 listen 80; # 基于域名的方式分配虚拟主机 server_name xxxxxxxxx.com; # 拦截路径 location /HanYiAPP_SystemManage { # 注意若是这里项目的context-path不为"/"则“http://tomcat-servers/project” project为项目的context-path proxy_pass http://tomcat-servers; proxy_redirect off; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $http_host; # 容灾处理 proxy_next_upstream http_502 http_504 error timeout invalid_header; #nginx跟后端服务器链接超时时间(代理链接超时) proxy_connect_timeout 600; #链接成功后,后端服务器响应时间(代理接收超时) proxy_read_timeout 600; #后端服务器数据回传时间(代理发送超时) proxy_send_timeout 600; #设置代理服务器(nginx)保存用户头信息的缓冲区大小 proxy_buffer_size 32k; #proxy_buffers缓冲区,网页平均在32k如下的话,这样设置 proxy_buffers 4 32k; #高负荷下缓冲大小(proxy_buffers*2) proxy_busy_buffers_size 64k; #设定缓存文件夹大小,大于这个值,将从upstream服务器传 proxy_temp_file_write_size 64k; } #文件服务器 location /file { # 容许跨域请求。全部链接均可跨域 add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Credentials' 'true'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; # 文件服务器根目录 root /home/public/hart_file; #是否能够访问目录下内容 autoindex on; # 是否展现真实文件大小 on:展现真实大小bytes autoindex_exact_size off; #是否展现文件时间为GMT时间 on : 文件服务器时间 autoindex_localtime on; add_header Cache-Control "no-cache, must-revalidate"; } }