Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andreas Nüßlein
committed
May 23, 2010
0 parents
commit 8ed5b4c
Showing
2 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ngx_addon_name=ngx_http_remote_ip_module | ||
HTTP_MODULES="$HTTP_MODULES ngx_http_remote_ip_module" | ||
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_remote_ip_module.c" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#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); | ||
|
||
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 */ | ||
}; | ||
|
||
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_buf_t *b; | ||
ngx_chain_t out; | ||
|
||
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); | ||
} | ||
|
||
static char *ngx_http_hello_world(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | ||
{ | ||
ngx_http_core_loc_conf_t *clcf; | ||
|
||
clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); | ||
clcf->handler = ngx_http_hello_world_handler; | ||
|
||
return NGX_CONF_OK; | ||
} |