Nginx安装配置
以core模块的server指令为例:
Syntax: server {…}Default:一Context:httpSyntax代表语法规则,Default代表默认值,Context代表在哪个模块中使用。
规则:
用〃”表示注释每行配置的结尾需要加上分号(漏了分号会导致无法启动)如果配置项值中包括语法符号,比如空格符,那么需要使用单引号或双引号括住配置项值,否则Nginx会报语法错误单位简写,当指定空间大小时,可以使用的单位包括: K或者k(千字节 KiloByte KB),M或者m(兆字节 MegaByte MB)比如gzip_buffers 48k; client_max_body_size 64M; 当指定时间时,可以使用的单位包括:ms (毫秒),s (秒),m (分钟),h (小 时),d (天),w (周,包含7天),M (月,包含30天),v (年,包含365天)。
例如
expires 10y; proxy_read_timeout 600; client_body_timeout 2m;基本配置项user administrator administrators; 配置用户或者组,默认为 nobody nobody。worker_processes 2;允许生成的进程数,默认为1pid /nginx/pid/nginx.pid; 指定 nginx 进程运行文件存放地址error_log log/error.log debug;制定日志路径,级别。这个设置可以放入全局块,http 块,server 块,级别以此为∶ debug|infolnotice|warn|error|crit|alertlemerg events{accept_mutex on; 设置网络连接序列化,防止惊群现象发生,默认为 on multi accept on; 设置一个进程是否同时接受多个网络连接,默认为 offuse epoll;事件驱动模型,selectpollkqueuelepoll|resig|/dev/polleventport worker_connections 1024;最大连接数,默认为 512}http { include mime.types;文件扩展名与文件类型映射表default_type application/octet-stream; 默认文件类型,默认为 text/plainaccess_log off; 取消服务日志log_format myFormat '$remote_addr-$remote_user [$time_local] $request $status $body _bytes_sent$http referer $http user agent $http x forwarded for'; 自定义格式 access_log log/access.log myFormat; combined 为日志格式的默认值sendfile on; 允许 sendfile 方式传输文件,默认为 off,可以在 http 块,server 块,location 块。 sendfile_max_chunk 100k;每个进程每次调用传输数量不能大于设定的值,默认为 0,即不设上限。keepalive timeout 65;连接超时时间,默认为75s,可以在 http,server,location 块。upstream mysvr { server 127.0.0.1:7878;server 192.168.10.121∶3333 backup;热备}error_page 404 https∶//www.baidu.com; 错误页 server {keepalive_requests 120; 单连接请求上限次数。 listen 4545; 监听端口 server_name 127.0.0.1; 监听地址location ~^.+${请求的 url 过滤,正则匹配,~为区分大小写,~为不区分大小写。root path; 根目录index vv.txt; 设置默认页proxy_pass http∶//mysvr;请求转向 mysvr 定义的服务器列表 deny 127.0.0.1; 拒绝的 ip allow 172.18.5.54;允许的 ip}}}3.Nginx基本命令在sbin目录下,加上./
4.Nginx 日志4.1 日志路径和内容
如果我们需要知道Nginx转发的请求的情况,比如来源IP、访问的URL、终端类型 等等,可以在Nginx中记录访问日志。如果Nginx运行发生了异常,也可以通过异常日 志找到原因。
日志路径在安装根路径logs目录下。日志主要有两种,access.log是访问日志, error.log是服务错误日志。access日志的内容格式是可以定制的。
4.2 日志配置
配置文件:nginx-reverse.conf
log_format main'$remote_user[$time_local] $http_x_Forwarded_for $remote_addr $request‘'$http_x_forwarded_for ''$upstream_addr '‘ups_resp_time: $upstream_response_time‘ ‘request_time: $request_time n';配置了日志内容格式之后,继续配置日志:可以使用的变量:
access_log path [format [buffer=size] [gzip[=level]] [flush=time][i仁condition]];总结一下,主要的模块是access log. Iog_format.
版权声明:本站内容来源于互联网收集,如果侵犯了您的版权,请与我们联系,我们将尽快处理!
扫码二维码
获取最新动态
