nginx学习(五) http模块

来源:互联网 发布:韩国人评论上瘾网络剧 编辑:程序博客网 时间:2024/05/29 19:46

一、http核心模块
1、alias
语法: alias file-path|directory-path;
默认值: no
作用域: location
该指令设置指定location使用的路径.注意它跟 root 相似,但是不改变文件的根路径,仅仅是使用文件系统路径
比如:
location  /i/ {
  alias  /spool/w3/images/;
}
请求 "/i/top.gif" 将返回文件 "/spool/w3/images/top.gif".
在替换路径中可以使用变量.
alias 无法在正则的 location中使用. 如果你需要这么做,你必须结合使用指令rewrite 和 root.

2、root
追加路径
syntax: root path
default: root html
context: http, server, location, if in location
root specifies the document root for the requests. For example, with this configuration
location  /i/ {
  root  /spool/w3;
}
A request for "/i/top.gif" will return the file "/spool/w3/i/top.gif". You can use variables in the argument.
root与alias区别:alias是将请求替换为alias的值。root是将请求追加到root后。看下面两个例子:

rootlocation ~ ^/awstats/ {        root  /home/awstats/;访问:http://test.com/awstats/ 实际访问的是/home/awstats/awstats/aliaslocation ~ ^/awstats/ {        alias  /home/访问:http://test.com/awstats/ 实际访问的是/home/

3、internal
只支持内部请求访问
error_page 404 /404.html;
location  /404.html {
  internal;
}

二、http log模块

1、access_log
语法: access_log path [format [buffer=size | off ] 默认值: access_log log/access.log combined
作用域: http, server, location
指令 access_log 指派路径、格式和缓存大小。

2、log_format
语法: log_format name format [format ...]
name为格式名称,可以在其他地方引用该格式。

log_format formatName 'format'access_log /user/access.log formatName
默认值: log_format combined "..."
作用域: http server

示例:

log_format  gzip  '$remote_addr - $remote_user [$time_local]  ': '"$request" $status $bytes_sent ': '"$http_referer" "$http_user_agent" "$gzip_ratio"';access_log  /spool/logs/nginx-access.log  gzip  buffer=32k;

上例中gzip为name,‘’中的内容为format



0 0