# Module nginx-multiport-module
---
## Instructions
Every worker process can bind own port, user can visit specific worker process by using the port.
- [ngx-stream-zone-module](doc/ngx-stream-zone-module.md)
Record stream's owner worker process slot
- [ngx-http-broadcast-module](doc/ngx-http-broadcast-module.md)
Broadcast HTTP request to all worker processes when receive HTTP request
## Directives
### multi\_listen
Syntax : multi_listen multiport relationport;
Default : None;
Context : events
multiport can configured as below:
address:port
port
unix:path
when configured with IPv4 or IPv6 port, worker process listen port plus with worker process's slot. For Example, we start four workers, add configured multiport with 9000. worker 0 will listen 9000, worker 1 will listen 9001, worker 2 will listen 9002, worker 3 will listen 9003
when configured with unix path, worker will listen path plus with suffix of worker process's slot. For Example, we start four workers, add configured multiport with unix:/tmp/http. worker 0 will listen /tmp/http.0, worker 1 will listen /tmp/http.1, worker 2 will listen /tmp/http.2, worker 3 will listen /tmp/http.3
relationport must configured same as listen directives in http server, rtmp server, stream server or other server
### inner\_proxy
Syntax : inner_proxy multiport uri;
Default : None;
Context : http, server, location
- multiport: configured in multi_listen
- uri: uri for inner_proxy, configured as below
location /multiport_test/ {
inner_proxy unix:/tmp/http.sock.80 /inner_proxy;
multiport_test;
}
location /inner_proxy/ {
rewrite ^/inner_proxy/(.*):/(.*) /$2 break;
proxy_pass http://$1:;
}
As example above, if send subrequest to process whose workerid is 0, the uri will change to /inner_proxy/unix:/tmp/http.sock.80.0:/multiport_test/xxx
proxy_pass will send current request to process 0 as inner proxy request.
## API
- ngx\_multiport\_get\_port
ngx_int_t ngx_event_multiport_get_port(ngx_pool_t *pool, ngx_str_t *port, ngx_str_t *multiport, ngx_int_t pslot);
- para:
pool: pool for port memory alloc
port: process real listen port while process\_slot is pslot
multiport: port configure for processes, format as below:
port only: port
IPv4: host:port host must be ipaddr of IPv4 or *
IPv6: [host]:port host must be ipaddr of IPv6
Unix: unix:/path
pslot: process\_slot, process\_slot of other worker process can get through ngx\_process\_slot\_get\_slot
- return value:
NGX\_OK for successd, NGX\_ERROR for failed
- ngx\_multiport\_get\_slot
ngx_int_t ngx_multiport_get_slot(ngx_uint_t wpid);
- para:
wpid: worker process id, 0 to ccf->worker_processes - 1
- return value:
ngx_process_slot for successd, NGX_ERROR for failed
- ngx\_http\_inner\_proxy\_request
ngx_int_t ngx_http_inner_proxy_request(ngx_http_request_t *r, ngx_int_t pslot);
send a inner proxy request to specific process, must use with directives inner\_proxy
- paras:
- r: http request for send inner request to sibling worker
- pslot: sibling worker ngx_process_slot
- return values:
- NGX_OK: for successd
- NGX_ERROR: for failed
- NGX_DECLINED: for not configured or send inner proxy to self
## Build
cd to NGINX source directory & run this:
./configure --add-module=/path/to/nginx-multiport-module/
make && make install
## Example
See t/ngx\_http\_process\_slot\_test\_module.c as reference
**Build**:
./configure --with-debug --with-ipv6 --add-module=/path/to/nginx-multiport-module/t/ --add-module=/path/to/nginx-multiport-module/ --add-module=/path/to/echo-nginx-module/
make && make install
**Configure**:
worker_processes 4;
events {
...
multi_listen 9000 80;
multi_listen unix:/tmp/http.sock.80 80;
}
http {
...
server {
...
location /multiport_test/ {
inner_proxy unix:/tmp/http.sock.80 /inner_proxy;
multiport_test;
}
location /inner_proxy/ {
rewrite ^/inner_proxy/(.*):/(.*) /$2 break;
proxy_pass http://$1:;
}
}
}
**Test for API**:
$ curl http://192.168.84.254/multiport_test/123
TEST cases 19, 19 pass
If request send to worker1 to worker3, the request will proxy to worker 0. will get log as below:
2017/10/14 20:45:44 [error] 20065#0: *6 multiport test handler, client: 192.168.84.1, server: localhost, request: "GET /multiport_test/123 HTTP/1.1", host: "192.168.84.254:9003"
2017/10/14 20:45:44 [error] 20065#0: *6 inner proxy return 0, client: 192.168.84.1, server: localhost, request: "GET /multiport_test/123 HTTP/1.1", host: "192.168.84.254:9003"
2017/10/14 20:45:44 [error] 20062#0: *8 multiport test handler, client: unix:, server: localhost, request: "GET //multiport_test/123 HTTP/1.0", host: "localhost"
**Test for multiport**:
curl -v http://127.0.0.1/
curl -v http://127.0.0.1:9000/
curl -v http://127.0.0.1:9001/
curl -v http://127.0.0.1:9002/
curl -v http://127.0.0.1:9003/
curl -v --unix-socket /tmp/http.sock.80.0 http:/
curl -v --unix-socket /tmp/http.sock.80.1 http:/
curl -v --unix-socket /tmp/http.sock.80.2 http:/
curl -v --unix-socket /tmp/http.sock.80.3 http:/
Tests will get the same result, for port 9000 will always send to worker process 0, 9001 to worker process 1 and so on
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
pingos-master.zip (224个子文件)
AUTHORS 143B
ngx_rtmp_hls_module.c 78KB
cJSON.c 76KB
ngx_rtmp_notify_module.c 62KB
ngx_mpegts_live_module.c 52KB
ngx_http_client.c 49KB
ngx_rtmp_codec_module.c 47KB
ngx_rtmp_dash_module.c 46KB
ngx_http_dynamic.c 43KB
ngx_rtmp_variables.c 40KB
cJSON_Utils.c 40KB
ngx_rtmp_exec_module.c 39KB
ngx_hls_http_module.c 37KB
ngx_ts_dash.c 36KB
ngx_live_record.c 35KB
ngx_rtmp_record_module.c 35KB
ngx_ts_stream.c 34KB
ngx_client.c 34KB
ngx_rtmp.c 34KB
ngx_rtmp_log_module.c 34KB
ngx_rtmp_core_module.c 33KB
ngx_rtmp_live_module.c 30KB
ngx_hls_live_module.c 30KB
ngx_ts_dash_mp4.c 30KB
ngx_rtmp_cmd_module.c 29KB
ngx_event_multiport_module.c 28KB
ngx_rtmp_dynamic.c 27KB
ngx_rtmp_handler.c 25KB
ngx_dynamic_conf.c 25KB
ngx_ts_hls.c 25KB
ngx_rtmp_control_module.c 23KB
ngx_rtmp_mp4.c 23KB
ngx_live_relay_rtmp.c 23KB
ngx_http_flv_live_module.c 22KB
ngx_rtmp_stat_module.c 22KB
ngx_mpegts_gop_module.c 21KB
ngx_dynamic_resolver.c 21KB
ngx_rtmp_gop_module.c 20KB
ngx_live_relay_static.c 19KB
ngx_rtmp_init.c 18KB
ngx_rtmp_handshake.c 17KB
ngx_rtmp_send.c 17KB
ngx_rtmp_amf.c 17KB
ngx_live_relay_httpflv.c 16KB
ngx_mpegts_http_module.c 16KB
ngx_rtmp_mpegts.c 16KB
ngx_stream_zone_module.c 15KB
ngx_http_trace_module.c 13KB
ngx_live_relay_simple.c 13KB
ngx_rtmp_monitor_module.c 12KB
ngx_live_stat.c 12KB
ngx_rtmp_access_module.c 12KB
ngx_live_relay_inner.c 11KB
ngx_rtmp_receive.c 11KB
ngx_live.c 11KB
ngx_live_relay.c 11KB
ngx_rtmp_shared_module.c 10KB
ngx_http_broadcast_module.c 9KB
ngx_toolkit_misc_test_module.c 9KB
ngx_toolkit_misc.c 9KB
ngx_http_dynamic_test_module.c 9KB
ngx_ts_avc.c 8KB
ngx_http_set_header.c 7KB
ngx_event_resolver.c 7KB
ngx_rbuf.c 7KB
ngx_http_inner_proxy_module.c 7KB
ngx_map_test_module.c 7KB
ngx_rtmp_eval.c 6KB
ngx_map.c 6KB
ngx_event_timer_module.c 6KB
ngx_timerd.c 6KB
ngx_http_ts_module.c 6KB
ngx_timerd_test_module.c 6KB
ngx_http_client_test_module.c 6KB
ngx_stream_ts_module.c 6KB
ngx_dynamic_conf_test_module.c 6KB
ngx_dynamic_resolver_test_module.c 6KB
ngx_multiport_test_module.c 6KB
ngx_rtmp_sys_stat_module.c 6KB
ngx_rtmp_limit_module.c 5KB
ngx_client_test_module.c 5KB
ngx_event_timer_test_module.c 5KB
ngx_process_slot_module.c 4KB
ngx_netcall.c 4KB
ngx_poold.c 4KB
ngx_event_resolver_test_module.c 4KB
ngx_multiport_misc.c 4KB
ngx_stream_zone_test_module.c 4KB
ngx_client_stat_module.c 4KB
ngx_rtmp_proxy_protocol.c 4KB
ngx_rbuf_test_module.c 3KB
ngx_poold_test_module.c 3KB
ngx_ts_aac.c 1KB
ngx_rtmp_bitop.c 1KB
ngx_rtmp_bandwidth.c 589B
nginx-core.conf 8KB
nginx-live.conf 8KB
nginx-idle-live.conf 8KB
nginx-edge.conf 7KB
nginx-edge.conf 7KB
共 224 条
- 1
- 2
- 3
头发不会掉
- 粉丝: 21
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0