TCP在高并发下访问比UNIX SOCKET 稳定,但UNIX SOCKET 速度要比TCP快
user nobody nobody;
--使用的用户和组
worker_processes 8;
--nginx的进程数,建议按照cpu数目来指定
worker_cpu_affinity 01 10;
--为每个进程分配cpu
error_log /usr/local/nginx/logs/nginx_error.log crit;
--指定错误日志的存放路径,错误日志记录级别可选项为:[debug|info|notice|warn|error|crit]
pid /usr/local/nginx/nginx.pid;
--指定pid存放的路径
worker_rlimit_nofile 65535;
--这个指令是指当一个nginx进程打开的最多文件描述符数目,理论值应该是最多打开文件数(ulimit -n)与nginx进程数相除,但是nginx分配请求并不是那么均匀,所以最好与ulimit -n的值保持一致。
events
{
use epoll;
--使用的网络I/O模型,linux推荐采用epoll,FreeBSD推荐采用kqueue
worker_connections 65535;
--每个进程允许的最多连接数,理论上每台nginx服务器的最大连接数为worker_processes*worker_connections
}
http
{
include mime.types;
--设定某种扩展名的文件用一种应用程序来打开的方式类型,当该扩展名文件被访问的时候,浏览器会自动使用指定应用程序来打开
default_type application/octet-stream;
--默认mine类型,是以流的形式下载文件,这样可以实现任意格式的文件下载
# charset gbk;
--设置使用的字符集,如果一个网站有多个字符集,请不要随便设置
server_names_hash_bucket_size 128;
--指定服务器名称哈希的大小,一般等于一路处理器缓存大小,服务器CPU的L1缓存的容量通常在32—256KB,
# client_header_buffer_size 32k;
# large_client_header_buffers 4 32k;
--设置客户端请求的header头缓冲区大小,当http 的uri太长或者request header 过大时会报414 Request URI too large 或者400 bad request
# client_max_body_size 8m;
--设置客户端能够上传的文件大小,HTTP请求的BODY 最大限制,若超出此值,报413 Request Entity Too Lager
server_tokens off;
--关闭错误时的版本显示
sendfile on;
--打开高效的文件传输模式,减少上下文切换次数和拷贝次数,提高web server的性能
tcp_nopush on;
--The options are enabled only when sendfile is used.
--Enabling the option allows:
--1.sending the response header and the beginning of a file in one packet, on Linux and FreeBSD 4.*;
--2.sending a file in full packets.
--sendfile开启的时候才起作用,调用tcp_cork方法,数据包不会马上传送出去,等到数据包最大时,一次性的传输出去,这样有助于解决网络堵塞。
keepalive_timeout 60;
--nginx http连接超时时间
tcp_nodelay on;
--The option is enabled only when a connection is transitioned into the keep-alive state.
(tcp_nodelay和tcp_nopush是互斥的。不过如果你同时设置了两个值的话,将会在第一个buf发送的时候,强制push数据,而第二个buf时,将会调用tcp_cork来打开nagle算法,也就是后面的都会应用tcp_nopush.)
fastcgi_connect_timeout 200;
--指定连接到后端FastCGI的超时时间。. It should be noted that this value can't exceed 75 seconds.
fastcgi_send_timeout 300;
--指定向FastCGI传送请求的超时时间,这个值是已经完成两次握手后向FastCGI传送请求的超时时间。
fastcgi_read_timeout 600;
--指定接收FastCGI应答的超时时间,这个值是已经完成两次握手后接收FastCGI应答的超时时间。
fastcgi_buffering on
--When buffering is enabled, nginx receives a response from the FastCGI server as soon as possible, saving it into the buffers set by the fastcgi_buffer_size and fastcgi_buffers directives. If the whole response does not fit into memory, a part of it can be saved to a temporary file on the disk. Writing to temporary files is controlled by the fastcgi_max_temp_file_size and fastcgi_temp_file_write_size directives.
fastcgi_buffer_size 4k;
--指定读取FastCGI应答第一部分需要用多大的缓冲区,一般第一部分应答不会超过1k,由于页面大小为4k,所以这里设置为4k。
fastcgi_buffers 8 4k;
--指定本地需要用多少和多大的缓冲区来缓冲FastCGI的应答请求
fastcgi_busy_buffers_size 128k;
--When buffering of responses from the FastCGI server is enabled, limits the total size of buffers that can be busy sending a response to the client while the response is not yet fully read. In the mean time, the rest of the buffers can be used for reading a response and, if needed, buffering part of a response to a temporary file. By default, size is limited by the size of two buffers set by the fastcgi_buffer_size and fastcgi_buffers directives.
# fastcgi_max_temp_file_size 1024m;
--This directive sets the maximum size of a temporary file
fastcgi_temp_file_write_size 128k;
--This directive sets the size of data written to a temporary file at a time
fastcgi_temp_path /dev/shm;
gzip on;
gzip_min_length 1k;
--Sets the minimum length of a response that will be gzipped
gzip_buffers 4 16k;
--Sets the number and size of buffers used to compress a response
gzip_http_version 1.1;
gzip_comp_level 2;
--设置gzip压缩等级,等级越底压缩速度越快文件压缩比越小,反之速度越慢文件压缩比越大,param:1-9
gzip_types text/plain application/x-javascript text/css application/xml;
--设置需要压缩的MIME类型,非设置值不进行压缩
gzip_vary on;
--和http头有关系,加个vary头,给代理服务器用的,有的浏览器支持压缩,有的不支持。因此,为避免浪费不支持的也压缩,需要根据客户端的HTTP头来判断,是否需要压缩。
阅读(442) | 评论(0) | 转发(0) |