nginx 모듈 구성
static ngx_command_t ngx_echo_commands[] = {
{
ngx_string("echo"), //
NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, //
ngx_echo_readconf, // . , handler
NGX_HTTP_LOC_CONF_OFFSET, // loc conf
offsetof(ngx_echo_loc_conf_t, ecdata), //
NULL //
},
ngx_null_command //command
};
nginx 는 몇 가지 기본 변환 함 수 를 제공 합 니 다:
ngx_conf_set_flag_slot: "on" 과 "off" 를 1 과 0 으로 바 꿉 니 다.
ngx_conf_set_str_slot: 문자열 을 ngx 로 포맷 합 니 다.str_t 형식
ngx_conf_set_num_slot: 숫자 를 분석 하고 정형 으로 변환 합 니 다.
ngx_conf_set_size_slot: 크기 를 나타 내 는 값 ("8k", "1m" 등) 을 해석 하고 size 로 포맷 합 니 다.t 형식
static char *
ngx_http_circle_gif(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{/*{{{*/
ngx_http_core_loc_conf_t *clcf;
ngx_http_circle_gif_loc_conf_t *cglcf = conf;
clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
clcf->handler = ngx_http_circle_gif_handler;
cglcf->enable = 1;
return NGX_CONF_OK;
}/*}}}*/
static ngx_http_module_t ngx_echo_module_ctx = {
NULL, /* preconfiguration */ ??? ?
NULL, /* postconfiguration */ ??? ?
NULL, /* create main configuration */
NULL, /* init main configuration */
NULL, /* create server configuration */
NULL, /* merge server configuration */
ngx_echo_create_loc_conf, /* create location configuration */
ngx_echo_merge_loc_conf /* merge location configuration */
};
create_loc_conf 는 구조 체 를 설정 하기 위 한 메모리 할당 등 설정 구조 체 를 초기 화 하 는 데 사 용 됩 니 다.
merge_loc_conf 는 부모 block 의 설정 정 보 를 이 구조 체 에 통합 하 는 데 사 용 됩 니 다. 즉, 설정 의 계승 을 실현 하 는 것 입 니 다.
static ngx_int_t ngx_echo_handler(ngx_http_request_t *r)
{
ngx_int_t rc;
ngx_buf_t *b;
ngx_chain_t out;
ngx_echo_loc_conf_t *cglcf;
cglcf = ngx_http_get_module_loc_conf(r, ngx_module_echo);
if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD))) {
return NGX_HTTP_NOT_ALLOWED;
}
if (r->headers_in.if_modified_since) {
return NGX_HTTP_NOT_MODIFIED;
}
r->headers_out.content_type.len = sizeof("text/html") - 1;
r->headers_out.content_type.data = (u_char *) "text/html";
r->headers_out.status = NGX_HTTP_OK;
r->headers_out.content_length_n = cglcf->ecdata.len;
if (r->method == NGX_HTTP_HEAD) {
rc = ngx_http_send_header(r);
if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
return rc;
}
}
b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
if (b == NULL) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "Failed to allocate response buffer.");
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
out.buf = b;
out.next = NULL;
b->pos = cglcf->ecdata.data;
b->last = cglcf->ecdata.data+(cglcf->ecdata.len);
b->memory = 1;
b->last_buf = 1;
rc = ngx_http_send_header(r);
if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
return rc;
}
return ngx_http_output_filter(r, &out);
}
ngx_module_t ngx_http_circle_gif_module = {
NGX_MODULE_V1,
&ngx_http_circle_gif_module_ctx, /* module context */
ngx_http_circle_gif_commands, /* module directives */
NGX_HTTP_MODULE, /* module type */
NULL, /* init master */
NULL, /* init module */
NULL, /* init process */
NULL, /* init thread */
NULL, /* exit thread */
NULL, /* exit process */
NULL, /* exit master */
NGX_MODULE_V1_PADDING
};
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
간단! Certbot을 사용하여 웹 사이트를 SSL(HTTPS)화하는 방법초보자가 인프라 주위를 정돈하는 것은 매우 어렵습니다. 이번은 사이트를 간단하게 SSL화(HTTP에서 HTTPS통신)로 변경하는 방법을 소개합니다! 이번에는 소프트웨어 시스템 Nginx CentOS7 의 환경에서 S...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.