Initial commit
This commit is contained in:
commit
904ce2292b
133
Dockerfile
Normal file
133
Dockerfile
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
FROM alpine:3.7
|
||||||
|
|
||||||
|
LABEL maintainer="aleksander@cynarski.pl"
|
||||||
|
|
||||||
|
ENV NGINX_VERSION 1.13.8
|
||||||
|
|
||||||
|
RUN CONFIG="\
|
||||||
|
--prefix=/etc/nginx \
|
||||||
|
--sbin-path=/usr/sbin/nginx \
|
||||||
|
--modules-path=/usr/lib/nginx/modules \
|
||||||
|
--conf-path=/etc/nginx/nginx.conf \
|
||||||
|
--error-log-path=/var/log/nginx/error.log \
|
||||||
|
--http-log-path=/var/log/nginx/access.log \
|
||||||
|
--pid-path=/var/run/nginx.pid \
|
||||||
|
--lock-path=/var/run/nginx.lock \
|
||||||
|
--http-client-body-temp-path=/var/cache/nginx/client_temp \
|
||||||
|
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
|
||||||
|
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
|
||||||
|
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
|
||||||
|
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
|
||||||
|
--user=nginx \
|
||||||
|
--group=nginx \
|
||||||
|
--with-http_ssl_module \
|
||||||
|
--with-http_realip_module \
|
||||||
|
--with-http_addition_module \
|
||||||
|
--with-http_sub_module \
|
||||||
|
--with-http_dav_module \
|
||||||
|
--with-http_flv_module \
|
||||||
|
--with-http_mp4_module \
|
||||||
|
--with-http_gunzip_module \
|
||||||
|
--with-http_gzip_static_module \
|
||||||
|
--with-http_random_index_module \
|
||||||
|
--with-http_secure_link_module \
|
||||||
|
--with-http_stub_status_module \
|
||||||
|
--with-http_auth_request_module \
|
||||||
|
--with-http_xslt_module=dynamic \
|
||||||
|
--with-http_image_filter_module=dynamic \
|
||||||
|
--with-http_geoip_module=dynamic \
|
||||||
|
--with-threads \
|
||||||
|
--with-stream \
|
||||||
|
--with-stream_ssl_module \
|
||||||
|
--with-stream_ssl_preread_module \
|
||||||
|
--with-stream_realip_module \
|
||||||
|
--with-stream_geoip_module=dynamic \
|
||||||
|
--with-http_slice_module \
|
||||||
|
--with-mail \
|
||||||
|
--with-mail_ssl_module \
|
||||||
|
--with-compat \
|
||||||
|
--with-file-aio \
|
||||||
|
--with-http_v2_module \
|
||||||
|
--add-module=/root/nginx-push-stream-module \
|
||||||
|
" \
|
||||||
|
&& addgroup -S nginx \
|
||||||
|
&& apk add --no-cache git openssh \
|
||||||
|
&& adduser -D -S -h /var/cache/nginx -s /sbin/nologin -G nginx nginx \
|
||||||
|
&& apk add --no-cache --virtual .build-deps \
|
||||||
|
gcc \
|
||||||
|
libc-dev \
|
||||||
|
make \
|
||||||
|
openssl-dev \
|
||||||
|
pcre-dev \
|
||||||
|
zlib-dev \
|
||||||
|
linux-headers \
|
||||||
|
curl \
|
||||||
|
gnupg \
|
||||||
|
libxslt-dev \
|
||||||
|
gd-dev \
|
||||||
|
geoip-dev \
|
||||||
|
&& curl -fSL https://nginx.org/download/nginx-$NGINX_VERSION.tar.gz -o nginx.tar.gz \
|
||||||
|
&& git clone https://github.com/wandenberg/nginx-push-stream-module.git /root/nginx-push-stream-module \
|
||||||
|
&& mkdir -p /usr/src \
|
||||||
|
&& tar -zxC /usr/src -f nginx.tar.gz \
|
||||||
|
&& rm nginx.tar.gz \
|
||||||
|
&& cd /usr/src/nginx-$NGINX_VERSION \
|
||||||
|
&& ./configure $CONFIG --with-debug \
|
||||||
|
&& make -j$(getconf _NPROCESSORS_ONLN) \
|
||||||
|
&& mv objs/nginx objs/nginx-debug \
|
||||||
|
&& mv objs/ngx_http_xslt_filter_module.so objs/ngx_http_xslt_filter_module-debug.so \
|
||||||
|
&& mv objs/ngx_http_image_filter_module.so objs/ngx_http_image_filter_module-debug.so \
|
||||||
|
&& mv objs/ngx_http_geoip_module.so objs/ngx_http_geoip_module-debug.so \
|
||||||
|
&& mv objs/ngx_stream_geoip_module.so objs/ngx_stream_geoip_module-debug.so \
|
||||||
|
&& ./configure $CONFIG \
|
||||||
|
&& make -j$(getconf _NPROCESSORS_ONLN) \
|
||||||
|
&& make install \
|
||||||
|
&& rm -rf /etc/nginx/html/ \
|
||||||
|
&& mkdir /etc/nginx/conf.d/ \
|
||||||
|
&& mkdir -p /usr/share/nginx/html/ \
|
||||||
|
&& install -m644 html/index.html /usr/share/nginx/html/ \
|
||||||
|
&& install -m644 html/50x.html /usr/share/nginx/html/ \
|
||||||
|
&& install -m755 objs/nginx-debug /usr/sbin/nginx-debug \
|
||||||
|
&& install -m755 objs/ngx_http_xslt_filter_module-debug.so /usr/lib/nginx/modules/ngx_http_xslt_filter_module-debug.so \
|
||||||
|
&& install -m755 objs/ngx_http_image_filter_module-debug.so /usr/lib/nginx/modules/ngx_http_image_filter_module-debug.so \
|
||||||
|
&& install -m755 objs/ngx_http_geoip_module-debug.so /usr/lib/nginx/modules/ngx_http_geoip_module-debug.so \
|
||||||
|
&& install -m755 objs/ngx_stream_geoip_module-debug.so /usr/lib/nginx/modules/ngx_stream_geoip_module-debug.so \
|
||||||
|
&& ln -s ../../usr/lib/nginx/modules /etc/nginx/modules \
|
||||||
|
&& strip /usr/sbin/nginx* \
|
||||||
|
&& strip /usr/lib/nginx/modules/*.so \
|
||||||
|
&& rm -rf /usr/src/nginx-$NGINX_VERSION \
|
||||||
|
\
|
||||||
|
# Bring in gettext so we can get `envsubst`, then throw
|
||||||
|
# the rest away. To do this, we need to install `gettext`
|
||||||
|
# then move `envsubst` out of the way so `gettext` can
|
||||||
|
# be deleted completely, then move `envsubst` back.
|
||||||
|
&& apk add --no-cache --virtual .gettext gettext \
|
||||||
|
&& mv /usr/bin/envsubst /tmp/ \
|
||||||
|
\
|
||||||
|
&& runDeps="$( \
|
||||||
|
scanelf --needed --nobanner --format '%n#p' /usr/sbin/nginx /usr/lib/nginx/modules/*.so /tmp/envsubst \
|
||||||
|
| tr ',' '\n' \
|
||||||
|
| sort -u \
|
||||||
|
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
|
||||||
|
)" \
|
||||||
|
&& apk add --no-cache --virtual .nginx-rundeps $runDeps \
|
||||||
|
&& apk del .build-deps \
|
||||||
|
&& apk del .gettext \
|
||||||
|
&& mv /tmp/envsubst /usr/local/bin/ \
|
||||||
|
\
|
||||||
|
# Bring in tzdata so users could set the timezones through the environment
|
||||||
|
# variables
|
||||||
|
&& apk add --no-cache tzdata \
|
||||||
|
\
|
||||||
|
# forward request and error logs to docker log collector
|
||||||
|
&& ln -sf /dev/stdout /var/log/nginx/access.log \
|
||||||
|
&& ln -sf /dev/stderr /var/log/nginx/error.log
|
||||||
|
|
||||||
|
COPY nginx.conf /etc/nginx/nginx.conf
|
||||||
|
COPY nginx.vh.default.conf /etc/nginx/conf.d/default.conf
|
||||||
|
|
||||||
|
EXPOSE 80
|
||||||
|
|
||||||
|
STOPSIGNAL SIGTERM
|
||||||
|
|
||||||
|
CMD ["nginx", "-g", "daemon off;"]
|
31
README.md
Normal file
31
README.md
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
# Nginx Push Stream Module
|
||||||
|
|
||||||
|
https://github.com/wandenberg/nginx-push-stream-module
|
||||||
|
|
||||||
|
|
||||||
|
## Budowanie obrazu
|
||||||
|
|
||||||
|
```
|
||||||
|
docker build -t nginx_push .
|
||||||
|
```
|
||||||
|
|
||||||
|
## Uruchomienie obrazu
|
||||||
|
|
||||||
|
```
|
||||||
|
docker run -p 8080:8080 nginx_push
|
||||||
|
```
|
||||||
|
|
||||||
|
## Przykłady użycia
|
||||||
|
|
||||||
|
W przeglądarce wchodzimy na adres:
|
||||||
|
[http://localhost:8080/sub/channel_1](http://localhost:8080/sub/channel_1)
|
||||||
|
|
||||||
|
|
||||||
|
W konsoli wpisujemy:
|
||||||
|
|
||||||
|
```
|
||||||
|
curl -s -v -X POST 'http://localhost:8080/pub?id=channel_1' -d 'Hello World!'
|
||||||
|
```
|
||||||
|
|
||||||
|
Tadam! ;]
|
||||||
|
|
40
nginx.conf
Normal file
40
nginx.conf
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
error_log /var/log/nginx/error.log warn;
|
||||||
|
pid /var/run/nginx.pid;
|
||||||
|
|
||||||
|
worker_processes 2;
|
||||||
|
|
||||||
|
events {
|
||||||
|
worker_connections 1024;
|
||||||
|
}
|
||||||
|
|
||||||
|
http {
|
||||||
|
postpone_output 1; # only postpone a single byte, default 1460 bytes
|
||||||
|
access_log /var/log/nginx-http_access.log;
|
||||||
|
|
||||||
|
push_stream_shared_memory_size 100m;
|
||||||
|
push_stream_max_channel_id_length 200;
|
||||||
|
# max messages to store in memory
|
||||||
|
push_stream_max_messages_stored_per_channel 20;
|
||||||
|
# message ttl
|
||||||
|
push_stream_message_ttl 5m;
|
||||||
|
# ping frequency
|
||||||
|
push_stream_ping_message_interval 30s;
|
||||||
|
# connection ttl to enable recycle
|
||||||
|
push_stream_subscriber_connection_ttl 15m;
|
||||||
|
# connection ttl for long polling
|
||||||
|
push_stream_longpolling_connection_ttl 30s;
|
||||||
|
push_stream_timeout_with_body off;
|
||||||
|
|
||||||
|
# wildcard
|
||||||
|
push_stream_wildcard_channel_prefix "broad_";
|
||||||
|
push_stream_wildcard_channel_max_qtd 3;
|
||||||
|
|
||||||
|
push_stream_message_template "{\"id\":~id~,\"channel\":\"~channel~\",\"text\":\"~text~\", \"tag\":\"~tag~\", \"time\":\"~time~\", \"eventid\":\"~event-id~\"}";
|
||||||
|
|
||||||
|
# subscriber may create channels on demand or only authorized (publisher) may do it?
|
||||||
|
push_stream_authorized_channels_only off;
|
||||||
|
|
||||||
|
push_stream_allowed_origins "*";
|
||||||
|
|
||||||
|
include /etc/nginx/conf.d/*.conf;
|
||||||
|
}
|
126
nginx.vh.default.conf
Normal file
126
nginx.vh.default.conf
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
server {
|
||||||
|
listen 8080 default_server;
|
||||||
|
server_name localhost;
|
||||||
|
|
||||||
|
|
||||||
|
location /pub {
|
||||||
|
# activate publisher mode for this location, with admin support
|
||||||
|
push_stream_publisher admin;
|
||||||
|
|
||||||
|
# query string based channel id
|
||||||
|
push_stream_channels_path $arg_id;
|
||||||
|
|
||||||
|
# store messages in memory
|
||||||
|
push_stream_store_messages on;
|
||||||
|
|
||||||
|
# Message size limit
|
||||||
|
# client_max_body_size MUST be equal to client_body_buffer_size or
|
||||||
|
# you will be sorry.
|
||||||
|
client_max_body_size 1m;
|
||||||
|
client_body_buffer_size 1m;
|
||||||
|
}
|
||||||
|
|
||||||
|
location ~ /sub/(.*) {
|
||||||
|
# activate subscriber mode for this location
|
||||||
|
push_stream_subscriber;
|
||||||
|
|
||||||
|
# positional channel path
|
||||||
|
push_stream_channels_path $1;
|
||||||
|
if ($arg_tests = "on") {
|
||||||
|
push_stream_channels_path "test_$1";
|
||||||
|
}
|
||||||
|
|
||||||
|
# header to be sent when receiving new subscriber connection
|
||||||
|
push_stream_header_template "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n<meta http-equiv=\"Cache-Control\" content=\"no-store\">\r\n<meta http-equiv=\"Cache-Control\" content=\"no-cache\">\r\n<meta http-equiv=\"Pragma\" content=\"no-cache\">\r\n<meta http-equiv=\"Expires\" content=\"Thu, 1 Jan 1970 00:00:00 GMT\">\r\n<script type=\"text/javascript\">\r\nwindow.onError = null;\r\ntry{ document.domain = (window.location.hostname.match(/^(\d{1,3}\.){3}\d{1,3}$/)) ? window.location.hostname : window.location.hostname.split('.').slice(-1 * Math.max(window.location.hostname.split('.').length - 1, (window.location.hostname.match(/(\w{4,}\.\w{2}|\.\w{3,})$/) ? 2 : 3))).join('.');}catch(e){}\r\nparent.PushStream.register(this);\r\n</script>\r\n</head>\r\n<body>";
|
||||||
|
|
||||||
|
# message template
|
||||||
|
push_stream_message_template "<div>p(~id~,'~channel~','~text~','~event-id~', '~time~', '~tag~');</div><br/>";
|
||||||
|
# footer to be sent when finishing subscriber connection
|
||||||
|
push_stream_footer_template "</body></html>";
|
||||||
|
# content-type
|
||||||
|
default_type "text/html; charset=utf-8";
|
||||||
|
|
||||||
|
if ($arg_qs = "on") {
|
||||||
|
push_stream_last_received_message_time "$arg_time";
|
||||||
|
push_stream_last_received_message_tag "$arg_tag";
|
||||||
|
push_stream_last_event_id "$arg_eventid";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
location ~ /ev/(.*) {
|
||||||
|
# activate event source mode for this location
|
||||||
|
push_stream_subscriber eventsource;
|
||||||
|
|
||||||
|
# positional channel path
|
||||||
|
push_stream_channels_path $1;
|
||||||
|
if ($arg_tests = "on") {
|
||||||
|
push_stream_channels_path "test_$1";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($arg_qs = "on") {
|
||||||
|
push_stream_last_received_message_time "$arg_time";
|
||||||
|
push_stream_last_received_message_tag "$arg_tag";
|
||||||
|
push_stream_last_event_id "$arg_eventid";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
location ~ /lp/(.*) {
|
||||||
|
# activate long-polling mode for this location
|
||||||
|
push_stream_subscriber long-polling;
|
||||||
|
|
||||||
|
# positional channel path
|
||||||
|
push_stream_channels_path $1;
|
||||||
|
if ($arg_tests = "on") {
|
||||||
|
push_stream_channels_path "test_$1";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($arg_qs = "on") {
|
||||||
|
push_stream_last_received_message_time "$arg_time";
|
||||||
|
push_stream_last_received_message_tag "$arg_tag";
|
||||||
|
push_stream_last_event_id "$arg_eventid";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
location ~ /jsonp/(.*) {
|
||||||
|
# activate long-polling mode for this location
|
||||||
|
push_stream_subscriber long-polling;
|
||||||
|
|
||||||
|
push_stream_last_received_message_time "$arg_time";
|
||||||
|
push_stream_last_received_message_tag "$arg_tag";
|
||||||
|
push_stream_last_event_id "$arg_eventid";
|
||||||
|
|
||||||
|
# positional channel path
|
||||||
|
push_stream_channels_path $1;
|
||||||
|
if ($arg_tests = "on") {
|
||||||
|
push_stream_channels_path "test_$1";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
location ~ /ws/(.*) {
|
||||||
|
# activate websocket mode for this location
|
||||||
|
push_stream_subscriber websocket;
|
||||||
|
|
||||||
|
# positional channel path
|
||||||
|
push_stream_channels_path $1;
|
||||||
|
if ($arg_tests = "on") {
|
||||||
|
push_stream_channels_path "test_$1";
|
||||||
|
}
|
||||||
|
|
||||||
|
# store messages in memory
|
||||||
|
push_stream_store_messages on;
|
||||||
|
|
||||||
|
push_stream_websocket_allow_publish on;
|
||||||
|
|
||||||
|
if ($arg_qs = "on") {
|
||||||
|
push_stream_last_received_message_time "$arg_time";
|
||||||
|
push_stream_last_received_message_tag "$arg_tag";
|
||||||
|
push_stream_last_event_id "$arg_eventid";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
location / {
|
||||||
|
#if (!-f $request_filename) {
|
||||||
|
# proxy_pass "http://localhost:8888";
|
||||||
|
#}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user