nginx配置文件nginx.conf详解

#运行的用户
#user nobody;

#启动进程数,通常设置成和cpu的数量相等
worker_processes 1;

#全局错误日志类型及PID文件

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;

#工作模式及连接上限
events {

  #单个后台worker process进程的最大并发连接数
  worker_connections 1024;

  #并发总数是 worker_processes和worker_connections的乘积
}


http {

  #设定mime类型,类型由mime.type文件定义
  include mime.types;
  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"';

  #access_log logs/access.log main;

  #sendfile 指令指定 nginx 是否调用 sendfile 函数(zero copy 方式)来输出文件

  sendfile on;
  #tcp_nopush on;

  #设置连接超时时间

  #keepalive_timeout 0;
  keepalive_timeout 65;

  #开启gzip压缩

  gzip_static on;
  gzip_proxied expired no-cache no-store private auth;
  gzip on;
  gzip_types application/javascript text/css text/javascript;

  #设定虚拟主机配置

server {

  #侦听端口号
  listen 80;

  #定义使用访问名称
  server_name localhost;

      #access_log logs/host.access.log main;

  #默认请求

  location / {

    #定义服务器的默认网站根目录位置
    root html;

    #定义首页索引文件的名称
    index index.html index.htm;
  }

  # 定义错误提示页面

  #error_page 404 /404.html;

  # redirect server error pages to the static page /50x.html
  #
  error_page 500 502 503 504 /50x.html;
  location = /50x.html {
    root html;
  }

  # proxy the PHP scripts to Apache listening on 127.0.0.1:80

  #location ~ .php$ {
    # proxy_pass http://127.0.0.1;
  #}

  # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  #PHP脚本全部转发到fastcgi处理
  #location ~ .php$ {
    # root html;
    # fastcgi_pass 127.0.0.1:9000;
    # fastcgi_index index.php;
    # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
    # include fastcgi_params;
  #}

  # deny access to .htaccess files, if Apache's document root
  # concurs with nginx's one

  #禁止访问 .htxxx 文件
  #location ~ /.ht {
    # deny all;
  #}
}

# another virtual host using mix of IP-, name-, and port-based configuration
#nginx可以设置的另外一个虚拟主机转发
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;

# location / {
# root html;
# index index.html index.htm;
# }
#}

# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;

# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;

# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;

# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;

# location / {
# root html;
# index index.html index.htm;
# }
#}

}