#指定Nginx Worker进程运行用户以及用户组 user www www; #指定了Nginx要开启的进程数,通常几个CPU就写几 worker_processes 2; #错误日志位置 error_log logs/error.log; #指定进程id的存储文件位置 pid logs/nginx.pid; #指定单进程打开文件数,需与系统设定一致 worker_rlimit_nofile 65535; events { #指定nginx工做模式,nginx主要的工做模式有select、poll、kqueue、epoll #其中select、poll是标准工做模式,kqueue、epoll为高效工做模式,epoll用在Linux系统中,而kqueue用在BSD系统中 use epoll; #指定单进程的最大链接数,即一个进程同时能处理1024个请求 worker_connections 1024; } #HTTP部分 http { #指定配置文件所包含的文件 include mime.types; #指定默认类型为二进制流,也就是当文件类型未定义时使用这种方式. #例如在没有配置PHP环境时,Nginx是不予解析的,此时,用浏览器访问PHP文件就会出现下载窗口 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"';; #设置容许客户端请求的最大的单个文件字节数 client_max_body_size 20m; #指定来自客户端请求头的headerbuffer大小,若是自定义了消息头或有更大的cookie,能够在这里增长缓冲大小 client_header_buffer_size 16k; #指定客户端请求中较大的消息头的缓存最大数量和大小,4为个数,32k为大小,最大缓存为4个32kb large_client_header_buffers 4 32k; #开启高效传输模式 sendfile on; #tcp_nopush,tcp_nodelay设置on,防止网络阻塞 tcp_nopush on; tcp_nodelay on; #指定客户端链接保持活动的超时时间 keepalive_timeout 65; #指定客户端请求头读取超时时间,若是超过这个时间,客户端尚未发送任何数据,Nginx将返回“Request time out(408)”错误 client_header_timeout 10; #指定客户端请求主体读取超时时间,若是超过这个时间客户端尚未发送任何数据,Nginx将返回“Request time out(408)”错误 client_body_timeout 10; #指定响应客户端的超时时间。这个超时仅限于两个链接活动之间的时间,若是超过这个时间,客户端没有任何活动,Nginx将会关闭链接 send_timeout 10; #开启gzip压缩,实时压缩输出数据流 gzip on; #设置容许压缩的页面最小字节数 gzip_min_length 1k; #指定内存空间来存贮压缩结果,这里指定4个单位为16k的内存来存储压缩结果,即总大小为64k gzip_buffers 4 16k; #指定识别HTTP协议版本,默认是1.1 gzip_http_version 1.1; #指定gzip压缩比,1 压缩比最小,处理速度最快;9 压缩比最大,传输速度快,但处理最慢,也比较消耗CPU资源 gzip_comp_level 2; #指定压缩的类型,不管是否指定,“text/html”类型老是会被压缩 gzip_types text/plain application/x-javascript text/css application/xml; #该选项开启可让前端的缓存服务器缓存通过gzip压缩的页面,例如,用Varnish缓存通过Nginx压缩的数据 gzip_vary on; #隐藏Nginx版本号 server_tokens off; #SERVER部分 server { #指定Nginx监端口 listen 8000; #用来指定IP或者域名 server_name localhost; #指定Nginx默认的字符集,只有utf-8支持中文字符 charset utf-8; #指定访问日志的名称及位置 access_log logs/host.access.log main; #可有多个location location / { #指定网页根目录 root /data/www/default.com; #设定默认首页 index index.html index.htm; #Nginx默认是不容许列出整个目录的,在server或location段里添加上 autoindex on;来启用目录浏览。 #开启目录浏览 autoindex on ; #默认为on,显示出文件的确切大小,单位是bytes。 #改成off后,显示出文件的大概大小,单位是kB或者MB或者GB autoindex_exact_size off ; #默认为off,显示的文件时间为GMT时间。 #改成on后,显示的文件时间为文件的服务器时间 autoindex_localtime on; } #开启目录浏览 location /down/ { #访问目录 alias /home/wwwroot/test/; autoindex on; } #指定错误页面 error_page 500 502 503 503 /50x.html; #定义错误页面,若是是500错误,则把站点根目录下的 50x.html 返给用户 location = /50x.html { root /data/www/www.error.com ; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} #配置PHP location ~ \.php$ { #指定网页根目录 root /data/www/default.com; #指定fastcgi的地址和端口 fastcgi_pass 127.0.0.1:9000; #默认页面 fastcgi_index index.php; #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; #配置fastcgi参数 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #引入fastcgi参数 include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one #location ~ /\.ht { # deny all; #} #指定url中包含jsp或者?的所有转发到192.168.0.10的80端口即tomcat处理 location ~ (jsp|\?) { proxy_pass http://192.168.0.10:80; } } #站点server,eg: www.default.com #可配置多个站点 server { listen 80; server_name www.default.com; root /data/www/www.default.com; index index.php index.html index.htm; location / { root /data/www/www.default.com; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /data/www/www.error.com ; } } #多个站点配置引入 #conf.d/www.site.com conf.d/www.site2.com include conf.d/* #其余说明 #针对单个域名请求作出单个链接超时的配置. #好比些动态解释和静态解释能够根据业务的需求配置 #proxy_connect_timeout :后端服务器链接的超时时间_发起握手等候响应超时时间 #proxy_read_timeout:链接成功后_等候后端服务器响应时间_其实已经进入后端的排队之中等候处理(也能够说是后端服务器处理请求的时间) #proxy_send_timeout :后端服务器数据回传时间_就是在规定时间以内后端服务器必须传完全部的数据