示例

http {
  server {
    listen          80;
    server_name     www.domain1.com;
    access_log      logs/domain1.access.log main;
    location / {
      index index.html;
      root  /var/www/domain1.com/htdocs;
    }
  }
  server {
    listen          80;
    server_name     www.domain2.com;
    access_log      logs/domain2.access.log main;
    location / {
      index index.html;
      root  /var/www/domain2.com/htdocs;
    }
  }
}

常用指令(Directives)

1. autoindex (启用目录浏览功能)

配置

location / {
    autoindex on;
}

参考:

  1. http://nginx.org/en/docs/http/ngx_http_autoindex_module.html

2. stub_status (启用访问 nginx 的状态信息)

配置

location /basic_status {
    stub_status on;
}

输出

Active connections: 2 
server accepts handled requests
 8 8 224 
Reading: 0 Writing: 1 Waiting: 1 

active connections – 活跃的连接数量
server accepts handled requests — 总共处理了n个连接 , 成功创建n次握手, 总共处理了n个请求
reading — 读取客户端的连接数.
writing — 响应数据到客户端的数量
waiting — 开启 keep-alive 的情况下,这个值等于 active – (reading+writing), 意思就是 Nginx 已经处理完正在等候下一次请求指令的驻留连接.

参考

  1. http://nginx.org/en/docs/http/ngx_http_stub_status_module.html

  2. http://www.ttlsa.com/nginx/nginx-status-detail/

3. access_log (记录请求日志)

参考

  1. http://nginx.org/en/docs/http/ngx_http_log_module.html

  2. http://www.ttlsa.com/linux/the-nginx-log-configuration/

4. rewrite (记录请求日志)

参考

  1. http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#rewrite

  2. http://blog.c1gstudio.com/archives/434


杨军军
1.3k 声望26 粉丝