#!nginx
: # 使用的用户和组
: user www www;
: # 指定工作衍生进程数
: worker_processes 2;
: # 指定 pid 存放的路径
: pid /var/run/nginx.pid;
: # [ debug | info | notice | warn | error | crit ]
: # 可以在下方直接使用 [ debug | info | notice | warn | error | crit ] 参数
: error_log /var/log/nginx.error_log info;
: events {
: # 允许的连接数
: connections 2000;
: # use [ kqueue | rtsig | epoll | /dev/poll | select | poll ] 见下方;
: use kqueue;
: }
: http {
: include conf/mime.types;
: default_type application/octet-stream;
: log_format main '$remote_addr - $remote_user [$time_local] '
: '"$request" $status $bytes_sent '
: '"$http_referer" "$http_user_agent" '
: '"$gzip_ratio"';
: log_format download '$remote_addr - $remote_user [$time_local] '
: '"$request" $status $bytes_sent '
: '"$http_referer" "$http_user_agent" '
: '"$http_range" "$sent_http_content_range"';
: client_header_timeout 3m;
: client_body_timeout 3m;
: send_timeout 3m;
: client_header_buffer_size 1k;
: large_client_header_buffers 4 4k;
: gzip on;
: gzip_min_length 1100;
: gzip_buffers 4 8k;
: gzip_types text/plain;
: output_buffers 1 32k;
: postpone_output 1460;
: sendfile on;
: tcp_nopush on;
: tcp_nodelay on;
: send_lowat 12000;
: keepalive_timeout 75 20;
: #lingering_time 30;
: #lingering_timeout 10;
: #reset_timedout_connection on;
: server {
: listen one.example.com;
: server_name one.example.com www.one.example.com;
: access_log /var/log/nginx.access_log main;
: location / {
: proxy_pass http://127.0.0.1/;
: proxy_redirect off;
: proxy_set_header Host $host;
: proxy_set_header X-Real-IP $remote_addr;
: #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
: client_max_body_size 10m;
: client_body_buffer_size 128k;
: client_body_temp_path /var/nginx/client_body_temp;
: proxy_connect_timeout 90;
: proxy_send_timeout 90;
: proxy_read_timeout 90;
: proxy_send_lowat 12000;
: proxy_buffer_size 4k;
: proxy_buffers 4 32k;
: proxy_busy_buffers_size 64k;
: proxy_temp_file_write_size 64k;
: proxy_temp_path /var/nginx/proxy_temp;
: charset koi8-r;
: }
: error_page 404 /404.html;
: location /404.html {
: root /spool/www;
: charset on;
: source_charset koi8-r;
: }
: location /old_stuff/ {
: rewrite ^/old_stuff/(.*)$ /new_stuff/$1 permanent;
: }
: location /download/ {
: valid_referers none blocked server_names *.example.com;
: if ($invalid_referer) {
: #rewrite ^/ http://www.example.com/;
: return 403;
: }
: #rewrite_log on;
: # rewrite /download/*/mp3/*.any_ext to /download/*/mp3/*.mp3
: rewrite ^/(download/.*)/mp3/(.*)\..*$
: /$1/mp3/$2.mp3 break;
: root /spool/www;
: #autoindex on;
: access_log /var/log/nginx-download.access_log download;
: }
: location ~* ^.+\.(jpg|jpeg|gif)$ {
: root /spool/www;
: access_log off;
: expires 30d;
: }
: }
: }
###################################################33
nginx处理事件模型
1、select:
select库是在linux和windows平台都基本支持的 事件驱动模型库,并且在接口的定义也基本相同,只是部分参数的含义略有差异,最大并发限制1024,只最早期的事件驱动模型。
2、poll:
在Linux 的基本驱动模型,windows不支持此驱动模型,是select的升级版,取消了最大的并发限制,在编译nginx的时候可以使用--with-poll_module和--without-poll_module这两个指定是否编译select库。
3、epoll:
epoll是库是Nginx服务器支持的最高性能的事件驱动库之一,是公认的非常优秀的事件驱动模型,它和select和poll有很大的区别,epoll是poll的升级版,但是与poll的效率有很大的区别.
epoll的处理方式是创建一个待处理的事件列表,然后把这个列表发给内核,返回的时候在去轮训检查这个表,以判断事件是否发生,epoll支持一个进程打开的最大事件描述符的上限是系统可以打开的文件的最大数,同时epoll库的IO效率不随描述符数目增加而线性下降,因为它只会对内核上报的“活跃”的描述符进行操作。
4、rtsig:
不是一个常用事件驱动,最大队列1024,不是很常用
5、kqueue:
用于支持BSD系列平台的高校事件驱动模型,主要用在FreeBSD 4.1及以上版本、OpenBSD 2.0级以上版本,NetBSD级以上版本及Mac OS X 平台上,该模型也是poll库的变种,因此和epoll没有本质上的区别,都是通过避免轮训操作提供效率。
6、/dev/poll:
用于支持unix衍生平台的高效事件驱动模型,主要在Solaris 平台、HP/UX,该模型是sun公司在开发Solaris系列平台的时候提出的用于完成事件驱动机制的方案,它使用了虚拟的/dev/poll设备,开发人员将要见识的文件描述符加入这个设备,然后通过ioctl()调用来获取事件通知,因此运行在以上系列平台的时候请使用/dev/poll事件驱动机制。
7、eventport:
该方案也是sun公司在开发Solaris的时候提出的事件驱动库,只是Solaris 10以上的版本,该驱动库看防止内核崩溃等情况的发生。