nginx的默认配置文件 conf/nginx.conf

#user  nobody;

使用的用户和组
worker_processes  1;

由主进程派生出的worker进程数(一般是cpu的总核数或它的2倍)

#error_log  logs/error.log  info;

指定错误日志的路径和级别 【debug|info|notice|warn|error|crit】

#pid        logs/nginx.pid;

pid的路径。

worker_rlimit_nofile 数值;

指定打开的文件描述符的数量。

events {

    use epoll;

 linux推荐epoll。
    worker_connections  1024;

允许的连接数
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    charset gb2312;

设置使用的字符集

    #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;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;

 

  ###################

 ######  补充内容

  server_names_hash_bucket_size 128;
  client_header_buffer_size 32k;
  large_client_header_buffers 4 32k;

  # 设置客户端能够上传的文件的大小
  client_max_body_size 8m;
  #sendfile 指令指定 nginx 是否调用 sendfile 函数(zero copy 方式) 来输出文件,
 #对于普通应用,必须设为 on。
 #如果用来进行下载等应用磁盘IO重负载应用,可设置为 off,以平衡磁盘与 网络IO处理速度,降低系统 uptime。

  sendfile on;
  tcp_nopush on;
  keepalive_timeout 60;
  tcp_nodelay on;

  fastcgi_connect_timeout 300;
  fastcgi_send_timeout 300;
  fastcgi_read_timeout 300;
  fastcgi_buffer_size 64k;
  fastcgi_buffers 4 64k;
  fastcgi_busy_buffers_size 128k;
  fastcgi_temp_file_write_size 128k;
 
 # 开启 gzip压缩  gzip on;
  gzip_min_length 1k;
  gzip_buffers 4 16k;
  gzip_http_version 1.1;
  gzip_comp_level 2;
  gzip _types text/plain application/x-javascript text/css application/xml;
  gzip_vary on;
 
  #limit_zone crawler $binary_remote_addr 10m;

  server
  {
   listen 80;
   # *.yourdomain.com 泛域名
   server_name www.yourdomain.com yourdomain.com *.yourdomain.com;
   index index.html index.htm index.php;
   root /data0/htdocs;
  
   ###############################
   ## location /
   ## {
   ##  index index.html index.htm;
   ##  root /data0/htdocs;
   ## }
   ################################

   # limit_conn crawler 20;

   location ~ .*\.(gif|jpg|gpeg|png|bmp|swf)$
  {
   expires 30d;
  }

   location ~.*\.(js|css)?$
  {
   expires 1h;
  }

   log_format access '$remote_addr - $remote_user [$time_local] "$request"'
   '$status $body_bytes_sent "$http_preferer"'
   '"$http_user_agent" $http_x_forwarded_for' ;

   access_log /data1/logs/access.log access;
  }
 }