nginx.conf配置说明
# 服务运行帐户
#user gisapp;
user nobody;
# 如果你的 Nginx 是多个 CPU 和多核,需要配置成多核的数量比较好
# worker_processes最多开启8个,8个以上性能就不会再提升了,而且稳定性会变的更低,因此8个进程够用了
worker_processes 8;
# 8核cpu,开启8个进程,cpu有多少个核,就有几位数,1代表内核开启,0代表内核关闭
worker_cpu_affinity 10000000 01000000 00100000 00010000 00001000 00000100 00000010 00000001;
# 如果 Nginx 服务很大的流量,增加最大可以打开的文件句柄还是很有用的,因为默认只有 1024 个,可以使用 'ulimit -n' 看到当前系统中的设置
worker_rlimit_nofile 65535;
# 错误日志,不要随意修改日志文件名称路径,日志切割脚本需要同步修改
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#error_log /log/nginx_logs/proxy.error.log crit;
# 进程编号文件,不要随意修改,服务重起和日志切割需要用到
pid logs/nginx.pid;
events {
#epoll是多路复用IO(I/O Multiplexing)中的一种方式,但是仅用于linux2.6以上内核,可以大大提高nginx的性能
use epoll;
#单个后台worker process进程的最大并发链接数
worker_connections 65535;
# max_clients = worker_connections * worker_processes
}
http {
include mime.types;
default_type application/octet-stream;
# 文字编码
#charset utf-8;
# 设定日志格式 ------------ S ----------------
# 注释:
#$remote_addr 与$http_x_forwarded_for 用以记录客户端的ip地址;
#$remote_user :用来记录客户端用户名称;
#$time_local : 用来记录访问时间与时区;
#$request : 用来记录请求的url与http协议;
#$status : 用来记录请求状态;成功是200,
#$body_bytes_s ent :记录发送给客户端文件主体内容大小;
#$http_referer :用来记录从那个页面链接访问过来的;
#$http_user_agent :记录客户浏览器的相关信息;
#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;
# 访问日志格式
log_format access_log_format '$remote_addr - $remote_user [$time_local] $request '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
# 访问日志文件,不要随意修改日志文件名称路径,日志切割脚本需要同步修改
#access_log /log/nginx_logs/proxy.access.log access_log_format;
# 关闭访问日志
access_log off;
# 设定日志格式 ------------ E ----------------
# sendfile 指令指定 nginx 是否调用 sendfile 函数(zero copy 方式)来输出文件,对于普通应用,
# 必须设为 on,如果用来进行下载等应用磁盘IO重负载应用,可设置为 off,以平衡磁盘与网络I/O处理速度,降低系统的uptime
sendfile on;
# 开启gzip压缩
gzip off;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
gzip_disable 'MSIE [1-6]\.';
server_names_hash_bucket_size 128;
#设定请求缓冲
# 客户端请求头部的缓冲区大小,这个可以根据你的系统分页大小来设置,
# 一般一个请求头的大小不会超过1k,不过由于一般系统分页都要大于1k,
# 所以这里设置为分页大小。 分页大小可以用命令getconf PAGESIZE 取得
# client_header_buffer_size该值必须设置为“系统分页大小”的整倍数
client_header_buffer_size 4k;
client_body_buffer_size 512k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
# 连接超时时间
#keepalive_timeout 0;
keepalive_timeout 60;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
tcp_nopush on;
tcp_nodelay on;
# 为了安全,关闭版本显示
server_tokens off;
# 注:proxy_temp_path和proxy_cache_path指定的路径必须在同一分区
proxy_temp_path /data/nginx/proxy_temp_path;
# 设置缓存区名称为cache_one,内存缓存空间大小为8192MB,1天没有被访问的内容自动清除,硬盘缓存空间大小为10GB。
# 注意这个配置是在server标签外,levels指定该缓存空间有两层hash目录,第一层目录是1个字母,第二层为2个字母,
# 保存的文件名就 会类似/path/to/cache/c/29/b7f54b2df7773722d382f4809d65029c;
# keys_zone为这个空间起个 名字,10m指空间大小为10MB;
# inactive的5m指缓存默认时长5分钟;max_size的2m是指单个文件超过2m的就不缓 存;
# clean_time指定一分钟清理一次缓存
proxy_cache_path /data/nginx/proxy_cache_path levels=1:2 keys_zone=cache_proxy:8192m inactive=5m max_size=10g;
#proxy_cache_path /data/nginx/proxy_cache_path levels=1:2 keys_zone=cache_proxy:10m inactive=10m max_size=1000M;
proxy_connect_timeout 60;
proxy_send_timeout 60;
proxy_read_timeout 60;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
# 路径规划和RangeSpider服务集群
upstream jxswapi {
server 115.231.73.253:80;
}
# HTTP
server
{
# 监听端口
listen 8889;
# 服务名称:域名或IP或localhost
#server_name gis.sit.shanghaionstar.com;
server_name localhost;
# TPI发布
location /jxtpi/ {
# 加载代理设定
include nginx_proxy.conf;
# 代理转发
proxy_pass http://jxswapi/jxtpi;
# 超时设定
expires 1d;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
root /data/tomcat/webapps/jxtpi;
if (-f $request_filename) {
expires 1d;
break;
}
}
location ~ .*\.(js|css)$
{
root /data/tomcat/webapps/jxtpi;
if (-f $request_filename) {
expires 1d;
break;
}
}
#用于清除缓存,假设一个URL为http://192.168.8.42/test.txt,通过访问http://192.168.8.42/purge/test.txt就可以清除该URL的缓存。
#location ~ /purge(/.*)
#{
# #设置只允许指定的IP或IP段才可以清除URL缓存。
# allow 127.0.0.1;
# allow 172.31.0.0/16;
# allow 10.16.33.0/24;
# allow 113.52.181.0/24;
# deny all;
# proxy_cache_purge cache_proxy $host$1$is_args$args;
#}
# 扩展名以.php、.jsp、.cgi结尾的动态应用程序不缓存。
#{ #location ~ .*\.(php|jsp|cgi)?$
# proxy_set_header Host $host;
# proxy_set_header X-Forwarded-For $remote_addr;
# proxy_pass http://jxswapi/jxtpi;
#}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
网友评论