Nginx服务器配置文件完全解析
userwwwwww;//使用的用户和组
worker_processes8;//指定的工作衍生进程数(一般等于cpu总核数或总核数的2倍)
error_loglogs/nginx_error.logcrit;//指定错误日志存放的路径,错误日志记录级别分别选项为:debug,info,notice,warn,error,crit
#error_loglogs/error.log;
#error_loglogs/error.lognotice;
#error_loglogs/error.loginfo;
pidnginx.pid;//指定pid文件存放的路径
#pidlogs/nginx.pid;
worker_rlimit_nofile65535;//一个nginx进程打开的最多文件描述符数目,理论值是最多打开的文件数(系统ulimit-n)与nginx进程数相除,但是nginx分配请求并不均匀,所以在这里建议和ulimit值保持一致
events{
useepoll;//使用网络I/O模型,Linux系统推荐采用epoll模型,FreeBSD系统推荐采用kqueue模型
worker_connections51200;//允许的连接数
}
#设定http服务器,利用它的反向代理功能提供负载均衡支持
http{
includemime.types;//设定mime类型,类型由mime.type文件定义
default_typeapplication/octet-stream;
charsetutf-8;//设置使用的字符集,如果一个网站有多种字符集,请不要随便设置,应该让程序员在HTML代码中通过Meta标签设置
ssion;//页面静态化的一个大问题是登陆用户访问如果静态化,大部分页面内容需要缓存但是用户登陆的个人信息是动态的,ssi用来解决页面部分缓存问题
ssi_silent_errorson;//默认是off,开启后在处理SSI文件出错时不输出错误提示:"[anerroroccurredwhileprocessingthedirective]"
ssi_typestext/shtml;//默认是ssi_typestext/html,所以如果需要htm和html支持,则不需要设置这句,如果需要shtml支持,则需要设置
#log_formatmain'$remote_addr-$remote_user[$time_local]"$request"'
#'$status$body_bytes_sent"$http_referer"'
#'"$http_user_agent""$http_x_forwarded_for"';
#access_loglogs/access.logmain;
#开启高效文件传输模式,sendfile指令指定nginx是否调用sendfile函数来输出文件,对于普通应用设为on,如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络I/O处理速度,降低系统的负载,如果图片显示不正常把这个改成off
sendfileon;
#tcp_nopushon;//防止网络阻塞
#tcp_nodelayon;
#autoindexoff;//开启目录列表访问,合适下载服务器,默认关闭
server_names_hash_bucket_size128;//服务器名字的hash表大小
client_header_buffer_size32k;//上传文件大小限制
large_client_header_buffers432k;//设定请求缓存
client_max_body_size300m;//设定请求缓存
#(与php-fpm有关)优化的上传支持,可以加速对大POST请求的处理速度,包括文件上传。优化是通过将请求体已写入一个临时文件,然后fastcgi协议传递文件名而不是请求体到来实现的
client_body_in_file_onlyclean;
client_body_temp_path/dev/shm12;
#这个参数设置比较大时,使用firefox或ie提交一个小于512K的图片访问都会正常,注释改指令模式大小是操作系统页面大小的两倍,8K或16K,一般提交的图片大于512K,提交的内容会写入到临时的文件,不会出现任何问题。当取消了目录访问权限(autoindexoff;),如果提交的图片大于512K都会返回500InternalServerError错误
client_body_buffer_size512k;
proxy_connect_timeout5;//后端服务器连接的超时时间_发起握手等候响应超时时间(代理连接超时)
proxy_read_timeout60;//连接成功后_等候后端服务器响应时间_其实已经进入后端的排队之中等候处理(后端服务器处理请求的时间)
proxy_send_timeout5;//后端服务器数据回传时间_就是在规定时间之内后端服务器必须传完所有的数据
proxy_buffer_size16k;//该指令设置缓冲区大小,从代理后端服务器取得的第一部分的响应内容,会放到这里,小的响应header通常位于这部分响应内容里边.(保存用户头信息的缓冲区大小)
proxy_buffers464k;//该指令设置缓冲区的大小和数量,从被代理的后端服务器取得的响应内容,会放置到这里.默认情况下,一个缓冲区的大小等于内存页面大小,可能是4K也可能是8K,这取决于平台
proxy_busy_buffers_size128k;//有处在busy状态的buffersize加起来不能超过proxy_busy_buffers_size,控制同时传输到客户端的buffer数量的
proxy_temp_file_write_size128k;//#临时文件写入大小
#nginx和cgi之间的超时时间
fastcgi_connect_timeout90;
fastcgi_send_timeout90;
fastcgi_read_timeout90;
fastcgi_buffer_size64k;
fastcgi_buffers464k;
fastcgi_busy_buffers_size128k;
fastcgi_temp_file_write_size128k;
#开启gzip压缩
gzipon;
gzip_min_length1k;
gzip_buffers416k;
#对http/1.1协议的请求才会进行压缩,如果使用了反向代理,那么nginx和后端的upstreamserver服务器是使用的1.0协议通信
gzip_http_version1.1;
gzip_comp_level9;
gzip_typestext/plainapplication/x-javascripttext/cssapplication/xml;
gzip_varyon;
#nginx缓存目录(在location段落下需要配合proxy_storeon开启缓存机制includeproxy.conf处理的详细规则
if(!-e$request_filename)){proxy_passhttp://192.168.10.10;}
proxy_temp_path/data/wwwroot/proxy_temp_dir;
#proxy_cache_path/data/wwwroot/cache.hxage.comlevels=1:2keys_zone=cache.hxage.com:3000minactive=1ymax_size=80G;
#Nginx内部重定向规则会被启动,当URL指向一个目录并且在最后没有包含“/”时,Nginx内部会自动的做一个301重定向,这时会有两种情况
#1、server_name_in_redirecton(默认),URL重定向为:server_name中的第一个域名+目录名+/;
#2、server_name_in_redirectoff,URL重定向为:原URL中的域名+目录名+/
server_name_in_redirectoff;
server_tokensoff;
#subfilter
#includesub_filter.conf;
#nullhostname
server{
listen80default;
return444;
access_logoff;
}
server
{
listen5566;
server_namelocalhost;
indexindex.htmlindex.htmindex.shtmlindex.php;
location~^/status/
{
stub_statuson;
access_logoff;
}
}
#----------------Vhost--------------------#
includevhost/*.conf;
}
#以下时阿里云主机上的一段nginx.conf配置文件
userwwwwww;
worker_processesauto;
error_log/alidata/log/nginx/error.logcrit;
pid/alidata/server/nginx/logs/nginx.pid;
#Specifiesthevalueformaximumfiledescriptorsthatcanbeopenedbythisprocess.
worker_rlimit_nofile65535;
events
{
useepoll;
worker_connections65535;
}
http{
includemime.types;
default_typeapplication/octet-stream;
#charsetgb2312;
server_names_hash_bucket_size128;
client_header_buffer_size32k;
large_client_header_buffers432k;
client_max_body_size8m;
sendfileon;
tcp_nopushon;
keepalive_timeout15;
tcp_nodelayon;
fastcgi_connect_timeout300;
fastcgi_send_timeout300;
fastcgi_read_timeout300;
fastcgi_buffer_size64k;
fastcgi_buffers464k;
fastcgi_busy_buffers_size128k;
fastcgi_temp_file_write_size128k;
gzipon;
gzip_min_length1k;
gzip_buffers416k;
gzip_http_version1.1;
gzip_comp_level2;
gzip_typestext/plainapplication/x-javascripttext/cssapplication/xml;
gzip_varyon;
gzip_disablemsie6;
#limit_zonecrawler$binary_remote_addr10m;
log_format'$remote_addr-$remote_user[$time_local]"$request"'
'$status$body_bytes_sent"$http_referer"'
'"$http_user_agent""$http_x_forwarded_for"';
include/alidata/server/nginx/conf/vhosts/*.conf;
}