root与alias区别
/usr/local/nginx 这个路径是nginx主路径server_name 匹对路径地址location 后面是匹对监听端口后的路径地址location /image {root /usr/local/nginx/image}客户端请求www.test.com/image/1.jpg,则对应磁盘映射路径/usr/local/nginx/image/image/1.jpglocation /image {root image 相对地址}则对应磁盘映射路径/usr/local/nginx/image/image/1.jpglocation /picture{alias /opt/nginx/html/picture;}客户端请求www.test.com/picture/1.jpg,则对应磁盘映射则对应磁盘映射路径/opt/nginx/html/picture/1.jpg
alias只能放在 location中
root能用在 http server location if中 类似全局参数一样
location 匹配规则
| 规则 | 含义 (优先级从高到低) | 示例 |
|---|---|---|
| = | 精确匹配 | location = /images/ {…} |
| ^~ | 匹配到即停止搜索 | location ^~ /images/ {…} |
| ~ | 正则匹配 区分大小写 | location ~ . (jpg | gif)$ { … } |
| ~* | 正则匹配 不区分大小写 | loaction ~*.(jpglgif)$ {…} 这个用得少 |
| 不带任何符号 | location / {..} |
结尾反斜线区别
/test 与 /test//test 先找目录 找不到 会尝试找test文件/test/ 只会当做文件目录
sub_status 模块
location /uri{stub_status;}也可以写在server层级
| 状态项 | 含义 |
|---|---|
| Active Connections | 活跃的连接数量 |
| accepts | 接受的客户端连接总数量 |
| handled | 处理的客户端连接总数量 |
| requests | 客户端总的请求数量 |
| Reading | 读取客户端的连接数 |
| Writing | 响应数据到客户端的连接数 |
| Waiting | 空闲客户端请求连接数量 |
