nginx的core模块
ngx_http_core_module提供了nginx最基本的功能, 包括一些内置变量和配置文件中的基本指令.
1. 常见内置变量
- uri相关
1 | $uri: 当前请求uri |
其中, nginx rewrite模块是基于内置变量$request_uri进行处理的.
- remote请求相关
1 | $remote_addr: 客户端地址 |
- server相关
1 | $server_addr: 接收请求的server地址 |
- 其它
1 | $hostname: nginx主机名 |
2. $host与$http_host
$http_host是对应http请求头的Host完整值.
$host是可能是以下几种情形中的一种(按顺序处理):
a. http请求url中的host name,
b. http请求header中的Host部分值(除去port),
c. 处理该请求server{}中的server_name.
3. location指令
1 | location [ = | ~ | ~* | ^~ ] uri { ... } |
可以被用在server/location等指令语句中.
location有两种匹配模式: prefix匹配(location uri)或者正则匹配.
nginx首先处理prefix匹配(无论配置文件中的顺序), 然后进行正则匹配.
匹配规则的含义:
1 | "": 前缀部分匹配 |
“location @..”是定义一个命名location, 通常用于请求重定向.
4. error_page指令
1 | error_page code ... [=[response]] uri; |
可以被用在http/server/location/if等指令语句中.
使用内部请求处理.
1 | error_page 404 /404.html; |
使用重定向进行处理.
1 | error_page 403 http://example.com/forbidden.html; |
使用命名location进行处理.
1 | location / { |

皖ICP备2026004021号-1