ngx_conf_read_token

复制代码
   file_size = ngx_file_size(&cf->conf_file->file.info);

此时 file_size=2656 当然还是和上次一样

复制代码
for ( ;; ) {
  if (b->pos >= b->last) {

此时

b->pos =0x57759a8b77f4

b->last = 0x57759a8b8230
b->start=0x57759a8b77d0

条件不成立

复制代码
ch = *b->pos++;
从缓冲区 b 的当前指针位置(b->pos)读取一个字符,并将指针后移一位

此时 ch 是一个换行符

处于配置第3行末尾,上一次再 分号处结束,然后是一个换行

配置文件

复制代码
#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #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;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

        if (ch == LF) {
            cf->conf_file->line++;
 
            if (sharp_comment) {
                sharp_comment = 0;
            }
        }

此时这个条件成立

line=3 变为 line=4

sharp_comment=0 第二个条件不成立

last_space=1

复制代码
if (last_space) {

            start = b->pos - 1;
            start_line = cf->conf_file->line;

            if (ch == ' ' || ch == '\t' || ch == CR || ch == LF) {
                continue;
            }

进入下一次循环

此时 ch 是一个换行,对应配置文件的第四行,一个空行

再次到达以上位置,

line=4 变为 line=5

然后进入下一次循环

这次 ch=#

复制代码
        if (last_space) {

进入这个条件

然后

复制代码
case '#':
                sharp_comment = 1;
                continue;

sharp_comment = 1

进入下一次循环

ch=e

sharp_comment=1

复制代码
        if (sharp_comment) {
            continue;
        }

然后进入下一次循环

ch=r

逻辑同上,因为 sharp_comment=1,这行是注释,所以会一直进入以上这个条件

直到遇到换行符

line=5 变为 line=6

进入下第6行

第6,7 行也是注释

第8行是空行,第9行是注释

然后是 空行

直到 12 行

来到12行

ch=e

sharp_comment=0
last_space=1

复制代码
            default:
                last_space = 0;

下一次循环

ch=v

逻辑同上

直到 ch= events后面的空格

复制代码
else if (ch == ' ' || ch == '\t' || ch == CR || ch == LF
                       || ch == ';' || ch == '{')
            {
                last_space = 1;
                found = 1;
            }

然后

复制代码
            if (found) {
                word = ngx_array_push(cf->args);
                if (word == NULL) {
                    return NGX_ERROR;
                }

                word->data = ngx_pnalloc(cf->pool, b->pos - 1 - start + 1);
                if (word->data == NULL) {
                    return NGX_ERROR;
                }

                for (dst = word->data, src = start, len = 0;
                     src < b->pos - 1;
                     len++)
                {

把 token保存到 cf->args

word->data=events

word->len=6

然后进入下一次循环

ch={

sharp_comment=0
last_space=1

复制代码
case '{':
                if (cf->args->nelts == 0) {
                    ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                                       "unexpected \"%c\"", ch);
                    return NGX_ERROR;
                }

                if (ch == '{') {
                    return NGX_CONF_BLOCK_START;
                }

                return NGX_OK;

进入这个条件

复制代码
                if (ch == '{') {
                    return NGX_CONF_BLOCK_START;
                }

这个条件成立

返回

相关推荐
海绵波波10711 分钟前
【部署】ubuntu部署olmOCR
linux·运维·ubuntu
自由鬼13 分钟前
OpenAI定义的Agent新范式如何构建自动化系统
运维·ai·自动化·agent
纪伊路上盛名在16 分钟前
vscode中修改快捷键
linux·ide·vscode·编辑器
自律的阿龙34 分钟前
Linux练级宝典->多线程
linux·运维·服务器
TravisBytes44 分钟前
在 VMware 中安装 Ubuntu 的超详细实战分享
linux·运维·ubuntu
小米先森1 小时前
Ubuntu “文件系统根目录”上的磁盘空间不足
linux·ubuntu
珹洺1 小时前
计算机网络:(一)详细讲解互联网概述与组成 (附带图谱更好对比理解)
服务器·开发语言·网络·数据库·后端·计算机网络·php
Tipriest_1 小时前
打包当前Ubuntu镜像 制作Ubuntu togo系统
linux·运维·ubuntu·ubuntu to go
敲上瘾1 小时前
共享内存通信效率碾压管道?System V IPC原理与性能实测
linux·运维·服务器·c++·算法·信息与通信
夜泉_ly1 小时前
项目日记 -云备份 -项目认识与环境搭建
linux·网络·c++