Skip to content

Commit f67eb87

Browse files
authored
Merge pull request #7 from tomatoy/wsgi-app
add location wsgi_pass variable
2 parents f7be8e8 + 224eb70 commit f67eb87

File tree

1 file changed

+51
-2
lines changed

1 file changed

+51
-2
lines changed

nginx/ngx_python_module.c

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,27 @@ static ngx_int_t ngx_python_postconfiguration(ngx_conf_t *cf);
1212
static wchar_t *python_exec = NULL;
1313

1414

15+
static void *ngx_http_wsgi_create_loc_conf(ngx_conf_t *cf);
16+
static char *ngx_handle_app(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
17+
static ngx_conf_post_t ngx_wsgi_pass_post = { ngx_handle_app };
18+
19+
typedef struct {
20+
ngx_str_t wsgi_pass;
21+
} ngx_wsgi_pass_conf_t;
22+
23+
static ngx_command_t ngx_wsgi_commands[] = {
24+
{ ngx_string("wsgi_pass"),
25+
NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_HTTP_LMT_CONF|NGX_CONF_TAKE1,
26+
ngx_conf_set_str_slot,
27+
NGX_HTTP_LOC_CONF_OFFSET,
28+
offsetof(ngx_wsgi_pass_conf_t, wsgi_pass),
29+
&ngx_wsgi_pass_post,
30+
},
31+
32+
ngx_null_command
33+
};
34+
35+
1536
static ngx_http_module_t ngx_python_module_ctx = {
1637
NULL, /* preconfiguration */
1738
ngx_python_postconfiguration, /* postconfiguration */
@@ -22,15 +43,15 @@ static ngx_http_module_t ngx_python_module_ctx = {
2243
NULL, /* create server configuration */
2344
NULL, /* merge server configuration */
2445

25-
NULL, /* create location configuration */
46+
ngx_http_wsgi_create_loc_conf, /* create location configuration */
2647
NULL /* merge location configuration */
2748
};
2849

2950

3051
ngx_module_t ngx_python_module = {
3152
NGX_MODULE_V1,
3253
&ngx_python_module_ctx, /* module context */
33-
NULL, /* module directives */
54+
ngx_wsgi_commands, /* module directives */
3455
NGX_HTTP_MODULE, /* module type */
3556
NULL, /* init master */
3657
NULL, /* init module */
@@ -96,3 +117,31 @@ ngx_python_postconfiguration(ngx_conf_t *cf) {
96117

97118
return NGX_OK;
98119
}
120+
121+
122+
static void *
123+
ngx_http_wsgi_create_loc_conf(ngx_conf_t *cf)
124+
{
125+
ngx_wsgi_pass_conf_t *conf;
126+
127+
conf = ngx_pcalloc(cf->pool, sizeof(ngx_wsgi_pass_conf_t));
128+
if (conf == NULL) {
129+
return NULL;
130+
}
131+
132+
return conf;
133+
}
134+
135+
136+
static char *
137+
ngx_handle_app(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
138+
{
139+
ngx_wsgi_pass_conf_t *wac = conf;
140+
if (wac->wsgi_pass.len > 0) {
141+
ngx_log_error(NGX_LOG_NOTICE, cf->log, 0, "get application %s", wac->wsgi_pass.data);
142+
} else {
143+
ngx_log_error(NGX_LOG_NOTICE, cf->log, 0, "no wsgi_pass found");
144+
}
145+
146+
return NGX_CONF_OK;
147+
}

0 commit comments

Comments
 (0)