内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

初識(shí)nginxhelloworld模塊

成都創(chuàng)新互聯(lián)公司專注于麗水網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠(chéng)為您提供麗水營(yíng)銷型網(wǎng)站建設(shè),麗水網(wǎng)站制作、麗水網(wǎng)頁(yè)設(shè)計(jì)、麗水網(wǎng)站官網(wǎng)定制、微信平臺(tái)小程序開(kāi)發(fā)服務(wù),打造麗水網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供麗水網(wǎng)站排名全網(wǎng)營(yíng)銷落地服務(wù)。1.nginx模塊

首先nginx和apache的不同就是nginx的模塊

vi /opt/nginx_hello_word/config

不能夠動(dòng)態(tài)添加,需要在編譯時(shí),指定要添加的模塊路徑,與nginx源碼一起編譯。
nginx模塊的處理流程:
a.客戶端發(fā)送http請(qǐng)求道nginx服務(wù)器
b.nginx基于配置文件中的位置選擇一個(gè)合適的處理模塊
c.負(fù)載均衡模塊選擇一臺(tái)后端服務(wù)器(反向代理情況下)
d.處理模塊進(jìn)行處理并把輸出緩沖放到第一個(gè)過(guò)濾模塊上
e.第一個(gè)過(guò)濾模塊處理后輸出給第二個(gè)過(guò)濾模塊
f.然后第二個(gè)過(guò)濾模塊又到第三個(gè)過(guò)濾模塊
g.第N個(gè)過(guò)濾模塊。。。
h.發(fā)處理結(jié)果發(fā)給客戶端

2.nginx模塊編寫(xiě)

a、創(chuàng)建模塊文件夾

mkdir -p /opt/nginx_hello_world cd /opt/nginx_hello_world

b、創(chuàng)建模塊配置文件

vi /opt/nginx_hello_word/config

寫(xiě)入內(nèi)容如下:

ngx_addon_name=ngx_http_hello_world_module HTTP_MODULES="$HTTP_MODULES ngx_http_hello_world_module" NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_hello_world_module.c"

c、創(chuàng)建模塊主文件

vi /opt/nginx_hello_world/ngx_http_hello_world_module.c

寫(xiě)入內(nèi)容如下:

#include <ngx_config.h> #include <ngx_core.h> #include <ngx_http.h> static char *ngx_http_hello_world(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); /* Commands */ static ngx_command_t ngx_http_hello_world_commands[] = { { ngx_string("hello_world"), NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS, ngx_http_hello_world, 0, 0, NULL }, ngx_null_command }; static u_char ngx_hello_world[] = "hello world"; static ngx_http_module_t ngx_http_hello_world_module_ctx = { NULL, /* preconfiguration */ NULL, /* postconfiguration */ NULL, /* create main configuration */ NULL, /* init main configuration */ NULL, /* create server configuration */ NULL, /* merge server configuration */ NULL, /* create location configuration */ NULL /* merge location configuration */ }; /* hook */ ngx_module_t ngx_http_hello_world_module = { NGX_MODULE_V1, &ngx_http_hello_world_module_ctx, /* module context */ ngx_http_hello_world_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 }; static ngx_int_t ngx_http_hello_world_handler(ngx_http_request_t *r) { /* ngx_int_t rc; */ ngx_buf_t *b; ngx_chain_t out; /* Http Output Buffer */ r->headers_out.content_type.len = sizeof("text/html;charset=utf-8") - 1; r->headers_out.content_type.data = (u_char *) "text/html;charset=utf-8"; b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t)); out.buf = b; out.next = NULL; b->pos = ngx_hello_world; b->last = ngx_hello_world + sizeof(ngx_hello_world); b->memory = 1; b->last_buf = 1; r->headers_out.status = NGX_HTTP_OK; r->headers_out.content_length_n = sizeof(ngx_hello_world); ngx_http_send_header(r); return ngx_http_output_filter(r, &out); } static char * ngx_http_hello_world(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_core_loc_conf_t *clcf ; /* register hanlder */ clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); clcf->handler = ngx_http_hello_world_handler; return NGX_CONF_OK; }

d、編譯

我的加了nginx_lua模塊,其他模塊等的。

./configure --prefix=/usr/local/nginx-1.9.6 --with-pcre=/root/pcre-8.36 --with-zlib=/root/zlib-1.2.8 --with-openssl=/root/openssl-1.0.2a --with-stream --with-stream_ssl_module --with-cpp_test_module --with-http_stub_status_module --with-http_degradation_module --with-http_secure_link_module --with-http_gzip_static_module --with-http_gunzip_module --with-http_sub_module --with-http_realip_module --with-http_v2_module --with-http_ssl_module --with-threads --add-module=/root/ngx_devel_kit-master --add-module=/root/lua-nginx-module-master --add-module=/root/echo-nginx-module-master --add-module=/root/stream-lua-nginx-module-master --add-module=/root/lua-upstream-nginx-module-master --add-module=/root/headers-more-nginx-module-master --add-module=/opt/nginx_hello_world

默認(rèn)只需要

./configure --prefix=/usr/local/nginx --add-module=/opt/nginx_hello_world/

make make install

e、配置nginx.conf

只需要在server域增加location

server { listen 83; server_name _; charset utf-8; access_log logs/tttt.access.log; location /helloworld { hello_world; } }

訪問(wèn):http://192.168.26.61:83/helloworld即可得到helloworld

3.hello world模塊分析

a. ngx_command_t函數(shù)用于定義包含模塊指令的靜態(tài)數(shù)組ngx_http_hello_world_commands

static ngx_command_t ngx_http_hello_world_commands[] = { { ngx_string("hello_world"), //設(shè)置指令名稱字符串,注意不能包含空格,數(shù)據(jù)類型ngx_str_t之后會(huì)詳細(xì)講解。 NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS, //配置指令的合法位置,這里表示:location部分合法,并且指令沒(méi)有參數(shù)。 ngx_http_hello_world,//回調(diào)函數(shù),三個(gè)參數(shù)(ngx_conf_t *cf,ngx_command_t *cmd, void *conf) 0,//后面的參數(shù)有待發(fā)掘,我還沒(méi)有用到 0, NULL }, ngx_null_command };

b.static u_char ngx_hello_world[] ="hello world" 則是輸出到屏幕的字符串。

c.ngx_http_module_t用來(lái)定義結(jié)構(gòu)體ngx_http_hello_world_module_ctx:

static ngx_http_module_t ngx_http_hello_world_module_ctx = { NULL, /* 讀入配置前調(diào)用*/ NULL, /* 讀入配置后調(diào)用*/ NULL, /* 創(chuàng)建全局部分配置時(shí)調(diào)用 */ NULL, /* 初始化全局部分的配置時(shí)調(diào)用*/ NULL, /* 創(chuàng)建虛擬主機(jī)部分的配置時(shí)調(diào)用*/ NULL, /* 與全局部分配置合并時(shí)調(diào)用 */ NULL, /* 創(chuàng)建位置部分的配置時(shí)調(diào)用 */ NULL /* 與主機(jī)部分配置合并時(shí)調(diào)用*/ };

d.ngx_module_t定義結(jié)構(gòu)體ngx_http_hello_world_module

ngx_module_t ngx_http_hello_world_module = { NGX_MODULE_V1, &ngx_http_hello_world_module_ctx, /* module context */ ngx_http_hello_world_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 };

他包含有模塊的主要內(nèi)容和指令的執(zhí)行部分,下一節(jié)會(huì)詳細(xì)講解。

e.處理函數(shù),ngx_http_hello_world_handler,也是hello world 模塊的核心部分。

static ngx_int_t ngx_http_hello_world_handler(ngx_http_request_t *r)//ngx_http_request_t *r 可以訪問(wèn)到客戶端的頭部和不久要發(fā)送的回復(fù)頭部 { /* ngx_int_t rc; */ ngx_buf_t *b; ngx_chain_t out; /* Http Output Buffer */ r->headers_out.content_type.len = sizeof("text/plain") - 1; r->headers_out.content_type.data = (u_char *) "text/plain"; b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t)); out.buf = b; out.next = NULL; b->pos = ngx_hello_world; b->last = ngx_hello_world + sizeof(ngx_hello_world); b->memory = 1; b->last_buf = 1; r->headers_out.status = NGX_HTTP_OK; r->headers_out.content_length_n = sizeof(ngx_hello_world); ngx_http_send_header(r); return ngx_http_output_filter(r, &out); }

網(wǎng)站標(biāo)題:初識(shí)nginxhelloworld模塊
網(wǎng)站地址:http://m.rwnh.cn/article22/cpojjc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營(yíng)銷、App開(kāi)發(fā)、品牌網(wǎng)站建設(shè)企業(yè)網(wǎng)站制作、網(wǎng)站收錄網(wǎng)站內(nèi)鏈

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)
千阳县| 吴桥县| 灵石县| 建瓯市| 奈曼旗| 运城市| 永福县| 黄梅县| 通山县| 石柱| 福贡县| 普安县| 石柱| 崇左市| 西城区| 杨浦区| 玉溪市| 都匀市| 老河口市| 偏关县| 阿城市| 鸡西市| 夏津县| 醴陵市| 红安县| 繁昌县| 福州市| 遵化市| 司法| 平潭县| 广州市| 老河口市| 中卫市| 商河县| 奉新县| 慈利县| 海城市| 孙吴县| 秦安县| 海城市| 五华县|