一个典型的nginx 配置如下:

user  nobody nobody;               # 运行nginx所属的组和所有者
worker_processes  2;               # 开启nginx的工作进程数,一般等于cpu核心数;新版支持auto
error_log  logs/error.log  notice; # 6个等级,默认为 crit,(debug, info, notice, warn, error, crit)
pid        logs/nginx.pid;         # pid路径

events {
    use epoll;
    worker_connections 65535; # 每个进程允许的最多连接数,ulimit -n 65535
}

http {
    include       mime.types;
    default_type  text/plain;
    charset  utf-8;
    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; # main 是给log_format起的名字
    sendfile       on;                 # 是否调用sendfile 函数 来输出文件,对于普通应用必须设为on
    tcp_nopush     on;                 # 允许或禁止使用socke的TCP_CORK的选项,仅在使用sendfile的时候使用
    gzip  on;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";
    server_tokens off;                 # 隐藏nginx版本号
    server_name_in_redirect off;       # 自动添加斜线”/”语句

    #降低timeout来降低dos攻击可能性
    keepalive_timeout  65;
    send_timeout 10;
    client_body_timeout 10;
    client_header_timeout 10;

    #设置自定义缓存降低缓存区溢出攻击可能性
    client_body_buffer_size  1K;
    client_max_body_size 1K;
    large_client_header_buffers 2 1K;

    server {
        listen       80;
        server_name  localhost 127.0.0.1;
        root /home/www.test.com;

        location ~ / {
           root   html;
           index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

    #include       /host/nginx/conf/vhost/www_test_com.conf;
    #include       /host/nginx/conf/vhost/www_test1_com.conf;
    #include       /host/nginx/conf/vhost/www_test2_com.conf;
    #include       /host/nginx/conf/vhost/*.conf;
}

-

-

备注说明

######【worker_processes】#######
# ps -ef | grep nginx
master监控进程充当整个进程组与用户的交互接口,同时对进程进行监护。它不需要处理网络事件,不负责业务的执行,
只会通过管理worker进程来实现重启服务、平滑升级、更换日志文件、配置文件实时生效等功能


######【nginx 事件模型】#######
支持的工作模式有select、poll、kqueue、epoll、rtsig和/dev/poll。
#每个子进程在ngx_worker_process_cycle()的循环里不断调用ngx_process_events_and_timers()函数来处理各种事件。
# 其中select和poll都是标准的工作模式,kqueue和epoll是高效的工作模式,
# 不同的是epoll用在Linux平台上,而kqueue用在BSD系统中。
# 对于Linux系统,epoll工作模式是首选。
# nginx采用epoll的事件模型,为何效率高 
  # nginx事件模型  http://zhan.renren.com/louxiaochang?gid=3602888498034749910&checked=true

######【worker_connections】#######
#官方的文档中找到这个参数
#理论上nginx作为http服务器的时候:
#max_clients = worker_processes * worker_connections/2
#理论上nginx作为反向代理服务器的时候:
#max_clients = worker_processes * worker_connections/4
#受单进程能打开的最大文件句柄数限制
#修改linux 最大文件限制数 ulimit -n 65535
#nginx并发数问题思考 http://www.tuicool.com/articles/2yUzem7


######【MIME type】#######
#定义MIME type到文件扩展名的映射。多个扩展名可以映射到同一个MIME type。
#当找不到相应的MIME type与文件扩展名之间的映射时,
#使用默认的MIME type作为HTTP header中的Content-Type。

results matching ""

    No results matching ""