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

这个条件成立

返回

相关推荐
对你无可奈何23 分钟前
高可用环境下Nginx服务管理脚本优化实践
linux·运维·nginx
前端白袍1 小时前
性能优化:服务器性能影响网站加载速度分析
运维·服务器·性能优化
无聊的烤苕皮1 小时前
RHCE(RHCSA复习:npm、dnf、源码安装实验)
linux·npm·云计算·dnf·rhcsa
xxxx1234451 小时前
Linux驱动开发-①pinctrl 和 gpio 子系统②并发和竞争③内核定时器
linux·驱动开发·单片机
stone08231 小时前
ABAP语言的动态编程(4) - 综合案例:管理费用明细表
linux·运维·服务器
厂里英才2 小时前
docker无法正常拉取镜像问题的解决
linux·docker
mljy.2 小时前
Linux《进度条》
linux
顾林海2 小时前
解锁Android应用进程启动:从代码到原理深度剖析
android·linux·操作系统
时之翼2 小时前
手把手教你用香橙派 OrangePi 5 搭建家用服务器
服务器
ღ星ღ2 小时前
网络编程基础
运维·服务器·网络