简要说明nginx的大的配置逻辑和方式,具体的细节,会有后续的章节做说明。
下面列举7个配置的原则
- 配置文件由指令与指令块构成
- 每条指令以分号(;)结尾,指令与参数间以空格符号分割,多个参数之间也是如此
- 指令块以大括号({})讲多条指令组织在一起
- 使用#号添加注释
- 使用$符号使用变量
- 部分指令的参数支持正则表达式
- include语句允许组合多个配置文件提升可维护性
下面说明具体的配置时间单位
ms -- millseconds
s -- seconds
m -- minutes
h -- hours
d -- days
w -- weeks
M --mouths
y -- years
下面为具体的空间单位
缺省 -- bytes
k/K -- kilobytes
m/M -- megabytes
g/G -- gigabytes
下面为对应的HTTP的配置指令块
http server(域名) location(url相关) upstream(上游服务相关)
具体的实例,这也是我本地的nginx.cof的一个配置的实例
http {
include mime.types;
default_type application/octet-stream;
access_log /Users/muyun/nginx/log/access.log main;
server {
listen 8020;
server_name localhost;
location / {
root /Users/muyun/nginx/www;
#alias /Users/muyun/nginx/www/;
index index.html index.htm index.php;
}
#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;
}
}
网友评论