• Post author:
  • Post category:nginx
  • Post comments:0评论

一、nginx相关文件

(1)Nginx主配置文件

路径 类型 作用
/etc/nginx/nginx.conf 配置文件 nginx主配置文件
/etc/nginx/conf.d/default.conf 配置文件 默认网站配置文件

(2)Nginx代理相关参数文件

路径 类型 作用
/etc/nginx/fastcgi_params 配置文件 Fastcgi代理配置文件(php)
/etc/nginx/scgi_params 配置文件 scgi代理配置文件
/etc/nginx/uwsgi_params 配置文件 uwsgi代理配置文件(python)

(3)Nginx编码相关配置文件

路径 类型 作用
/etc/nginx/win-utf 配置文件 Nginx编码转换映射文件
/etc/nginx/koi-utf 配置文件 Nginx编码转换映射文件
/etc/nginx/koi-win 配置文件 Nginx编码转换映射文件
/etc/nginx/mime.types 配置文件 Content-Type与扩展名,nginx支持的数据类型

(4)Nginx管理相关命令

路径 类型 作用
/usr/sbin/nginx 命令 Nginx命令行管理终端工具
/usr/sbin/nginx-debug 命令 Nginx命令行与终端调试工具

(5)Nginx日志相关文件

路径 类型 作用
/var/log/nginx/access.log 日志文件 nginx访问日志
/var/log/nginx/error.log 日志文件 nginx错误日志
/etc/logrotate.d/nginx 配置文件 Nginx默认的日志切割

二、主配置文件解析

[root@web02 ~]# cat /etc/nginx/nginx.conf
#---------------------------核心模块------------------------------
#启动用户
user  www;
#工作进程数
worker_processes  1;
#错误日志       debug/info/notice/warn/error/emeor
error_log  /var/log/nginx/error.log warn;
#pid文件
pid        /var/run/nginx.pid;

#---------------------------事件驱动模块---------------------------
#事件
events {
    #工作进程的连接数
    worker_connections  1024;
}

#------------------------------http内核模块------------------------
#网站配置
http {
    #nginx包含的文件类型
    include       /etc/nginx/mime.types;
    #当遇到nginx不识别的文件就会下载
    default_type  application/octet-stream;
    #日志格式   日志格式的名字
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    #访问日志及调用格式
    access_log  /var/log/nginx/access.log  main;
    #开启文件高效传输模式,一般配合tcp_nopush和tcp_nodelay使用。
    sendfile       on;
    #tcp_nopush和tcp_nodelay“互斥”。它可以配置一次发送数据包的大小。也就是说,数据包累积到一定大小后再发送,必须和sendfile配合使用。    
    #tcp_nopush    on;
    #不积累拼接数据小包,按时间累计0.2 秒后发送包。
    #tcp_nodelay   on;
    #保持长连接
    keepalive_timeout  65;
    #压缩
    #gzip  on;
    #包含的配置文件
    include /etc/nginx/conf.d/*.conf;

    server {
        #服务监听端口
        listen       80;
        #域名
        server_name  localhost;
        #字符集
        charset utf-8;
        #请求的地址
        location / {
            #站点目录,当访问/的时候跳转目录
            root   /usr/share/nginx/html;
            #默认访问页面
            index  index.html index.htm;
        }
    }
}

三、日志格式

http {

    ....

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    ....
}

$remote_addr    # 记录客户端IP地址
$remote_user    # 记录客户端用户名
$time_local     # 记录本地时间
$time_iso8601   # 记录ISO8601标准格式下的本地时间
$request        # 记录请求的方法以及请求的http协议 (http1.0:短连接,一次TCP连接仅发起一次请求,http1.1:长连接,一次TCP连接发起多次请求)
$status             # 记录请求状态码(用于定位错误信息)
$body_bytes_sent    # 发送给客户端的资源字节数,不包括响应头的大小
$bytes_sent         # 发送给客户端的总字节数
$msec               # 日志写入时间。单位为秒,精度是毫秒。
$http_referer       # 记录从哪个页面链接访问过来的
$http_user_agent    # 记录客户端浏览器相关信息
$http_x_forwarded_for   #记录客户端真实IP地址
$request_length         # 请求的长度(包括请求行, 请求头和请求正文)。
$request_time           # 请求花费的时间,单位为秒,精度毫秒

发表回复

验证码: 56 − 55 =