加入收藏 | 设为首页 | 会员中心 | 我要投稿 温州站长网 (https://www.0577zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 搭建环境 > Unix > 正文

当初我要是这么学习Nginx就好了!(多图详解)

发布时间:2020-03-24 19:57:20 所属栏目:Unix 来源:站长网
导读:副标题#e# 【51CTO.com原创稿件】本文主要帮助大家熟悉 Nginx 有哪些应用场景、Nginx 特点和架构模型以及相关流程、Nginx 定制化开发的几种模块分类。读完本文你将对 Nginx 有一定的认识。 图片来自 Pexels 本文将围绕如下几个部分进行讲解: Nginx 简介及

    ngx_buf_t                               *b; 

    ngx_chain_t                             out; 

    ngx_http_test_conf_t                    *lrcf; 

    ngx_str_t                               ngx_test_string = ngx_string("hello test"); 

 

    lrcf = ngx_http_get_module_loc_conf(r, ngx_http_test_module); 

    if ( lrcf->test_counter == 0 ) { 

        return NGX_DECLINED; 

    } 

 

    /* we response to 'GET' and 'HEAD' requests only */ 

    if ( !(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD)) ) { 

            return NGX_HTTP_NOT_ALLOWED; 

    } 

 

    /* discard request body, since we don't need it here */ 

    rc = ngx_http_discard_request_body(r); 

 

    if ( rc != NGX_OK ) { 

        return rc; 

    } 

 

    /* set the 'Content-type' header */ 

    /* 

     *r->headers_out.content_type.len = sizeof("text/html") - 1; 

     *r->headers_out.content_type.data = (u_char *)"text/html"; 

    */ 

    ngx_str_set(&r->headers_out.content_type, "text/html"); 

 

    /* send the header only, if the request type is http 'HEAD' */ 

    if ( r->method == NGX_HTTP_HEAD ) { 

        r->headers_out.status = NGX_HTTP_OK; 

        r->headers_out.content_length_n = ngx_test_string.len; 

 

        return ngx_http_send_header(r); 

    } 

 

    /* set the status line */ 

    r->headers_out.status = NGX_HTTP_OK; 

    r->headers_out.content_length_n =  ngx_test_string.len; 

 

    /* send the headers of your response */ 

    rc = ngx_http_send_header(r); 

    if ( rc == NGX_ERROR || rc > NGX_OK || r->header_only ) { 

        return rc; 

    } 

 

    /* allocate a buffer for your response body */ 

    b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t)); 

    if ( b == NULL ) { 

        return NGX_HTTP_INTERNAL_SERVER_ERROR; 

    } 

 

    /* attach this buffer to the buffer chain */ 

    out.buf = b; 

    out.next = NULL; 

 

    /* adjust the pointers of the buffer */ 

    b->pos = ngx_test_string.data; 

    b->last = ngx_test_string.data + ngx_test_string.len; 

(编辑:温州站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读