Nginx的配置文件其实是一个普通的文本文件。
user nobody;
worker_processes 8;
error_log varlog/nginx/error.log error;
#pid logs/nginx.pid;
events {use epoll;worker_connections 50000;
}
http {include mime.types;default_type application/octet-stream;log_format main '$remote_addr [$time_local] "$request" ''$status $bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';access_log logs/access.log main buffer=32k;…
}
1、块配置项
块配置项由一个块配置项名和一对大括号组成。
events {…
}
http {upstream backend {server 127.0.0.1:8080;}gzip on;server {…location /webstatic {gzip off;}}
}
2、配置项的语法格式
配置项名 1配置项值 2配置项值 … ;
首先,在行首的是配置项名,这些配置项名必须是Nginx的某一个模块想要处理的,配置项名输入结束后,将以空格作为分隔符。
其次是配置项值,它可以是数字或字符串(当然也包括正则表达式)。可以包含多个值,配置项值之间仍然由空格符来分隔。
最后,每行配置的结尾需要加上分号。
注意:如果配置项值中包括语法符号,比如空格符,那么需要使用单引号或双引号括住配置项值。
log_format main '$remote_addr - $remote_user [$time_local] "$request" ';
3、配置项的注释
#pid logs/nginx.pid;
4、配置项的单位
当指定空间大小时,可以使用的单位包括:
·K或者k千字节(KiloByte,KB)。
·M或者m兆字节(MegaByte,MB)。
gzip_buffers 4 8k;
client_max_body_size 64M;
当指定时间时,可以使用的单位包括:
ms(毫秒),
s(秒),
m(分钟),
h(小时),
d(天),
w(周,包含7天),
M(月,包含30天),
y(年,包含365天)。
expires 10y;
proxy_read_timeout 600;
client_body_timeout 2m;
5、在配置中使用变量
log_format main '$remote_addr - $remote_user [$time_local] "$request" ''$status $bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';
remote_addr是一个变量,使用它的时候前面要加上$符号。