欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 科技 > 能源 > ngx_conf_read_token

ngx_conf_read_token

2025/3/16 8:02:26 来源:https://blog.csdn.net/weixin_41812346/article/details/146282663  浏览:    关键词: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;}

这个条件成立

返回

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词