Last active
March 23, 2020 20:47
-
-
Save kantale/fc5d09cf625234bd499d11fbb42075e7 to your computer and use it in GitHub Desktop.
netdata + nginx as proxy
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
FROM ubuntu:16.04 | |
RUN apt-get update && \ | |
apt-get install -y uuid-dev zlib1g-dev gcc make autoconf automake pkg-config libtool libpcre3-dev wget && \ | |
wget -O "libuv-v1.35.0.tar.gz" https://github.com/libuv/libuv/archive/v1.35.0.tar.gz && \ | |
tar zxvf libuv-v1.35.0.tar.gz && \ | |
mkdir -p /libuv-build && \ | |
(cd libuv-1.35.0/; sh autogen.sh; ./configure --prefix=/libuv-build; make; make install) | |
RUN mkdir -p /netdata-build && \ | |
wget -O "netdata-v1.20.0.tar.gz" https://github.com/netdata/netdata/releases/download/v1.20.0/netdata-v1.20.0.tar.gz && \ | |
tar zxvf netdata-v1.20.0.tar.gz && \ | |
export CFLAGS="-L/libuv-build/lib/ -I/libuv-build/include/" && \ | |
(cd netdata-v1.20.0/; bash netdata-installer.sh --install /netdata-build --dont-start-it --disable-https --dont-wait ) | |
RUN wget -O "nginx-1.16.1.tar.gz" http://nginx.org/download/nginx-1.16.1.tar.gz && \ | |
tar zxvf nginx-1.16.1.tar.gz && \ | |
mkdir -p /nginx-build && \ | |
(cd nginx-1.16.1/; ./configure --prefix=/nginx-build ; make; make install) | |
# RUN cp /nginx-build/conf/nginx.conf /nginx-build/conf/nginx.conf.back && \ | |
COPY nginx.conf /nginx-build/conf/nginx.conf | |
COPY netdata.conf /netdata-build/netdata/etc/netdata/netdata.conf | |
ENV LD_LIBRARY_PATH /libuv-build/lib/ | |
# START NETDATA | |
# /netdata-build/netdata/usr/sbin/netdata | |
# START NGINX | |
# /nginx-build/sbin/nginx | |
EXPOSE 8080 | |
CMD /netdata-build/netdata/usr/sbin/netdata && /nginx-build/sbin/nginx | |
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
[web] | |
allow connections from = localhost |
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
INSTALLDIR=/home/ubuntu | |
ID=mitsaklas | |
sudo apt-get install -y uuid-dev zlib1g-dev gcc make autoconf automake pkg-config libtool libpcre3-dev | |
# INSTALL LIBUV FROM SOURCE | |
wget -O "libuv-v1.35.0.tar.gz" https://github.com/libuv/libuv/archive/v1.35.0.tar.gz | |
tar zxvf libuv-v1.35.0.tar.gz | |
mkdir -p ${INSTALLDIR}/libuv-build | |
(cd libuv-1.35.0/; sh autogen.sh; ./configure --prefix=${INSTALLDIR}/libuv-build; make; make install) | |
# INSTALL NETDATA FROM SOURCE | |
mkdir -p ${INSTALLDIR}/netdata-build | |
wget -O "netdata-v1.20.0.tar.gz" https://github.com/netdata/netdata/releases/download/v1.20.0/netdata-v1.20.0.tar.gz | |
tar zxvf netdata-v1.20.0.tar.gz | |
export CFLAGS="-L${INSTALLDIR}/libuv-build/lib/ -I${INSTALLDIR}/libuv-build/include/" | |
(cd netdata-v1.20.0/; bash netdata-installer.sh --install ${INSTALLDIR}/netdata-build --dont-start-it --disable-https --dont-wait ) | |
# INSTALL NGINX FROM SOURCE | |
wget -O "nginx-1.16.1.tar.gz" http://nginx.org/download/nginx-1.16.1.tar.gz | |
tar zxvf nginx-1.16.1.tar.gz | |
mkdir -p ${INSTALLDIR}/nginx-build | |
(cd nginx-1.16.1/; ./configure --prefix=${INSTALLDIR}/nginx-build ; make; make install) | |
# CONFIGURE NGINX | |
cp ${INSTALLDIR}/nginx-build/conf/nginx.conf ${INSTALLDIR}/nginx-build/conf/nginx.conf.backup | |
cat > ${INSTALLDIR}/nginx-build/conf/nginx.conf << EOF | |
#user nobody; | |
worker_processes 1; | |
#error_log logs/error.log; | |
#error_log logs/error.log notice; | |
#error_log logs/error.log info; | |
#pid logs/nginx.pid; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
include mime.types; | |
#include sites-enabled/*; | |
default_type application/octet-stream; | |
#log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | |
# '$status $body_bytes_sent "$http_referer" ' | |
# '"$http_user_agent" "$http_x_forwarded_for"'; | |
#access_log logs/access.log main; | |
sendfile on; | |
#tcp_nopush on; | |
#keepalive_timeout 0; | |
keepalive_timeout 65; | |
#gzip on; | |
upstream ${ID} { | |
server 127.0.0.1:19999; | |
keepalive 64; | |
} | |
server { | |
listen 8080; | |
# the virtual host name of this subfolder should be exposed | |
#server_name netdata.example.com; | |
location = /${ID} { | |
return 301 /${ID}/; | |
} | |
location ~ /${ID}/(?<ndpath>.*) { | |
proxy_redirect off; | |
proxy_set_header Host \$host; | |
proxy_set_header X-Forwarded-Host \$host; | |
proxy_set_header X-Forwarded-Server \$host; | |
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; | |
proxy_http_version 1.1; | |
proxy_pass_request_headers on; | |
proxy_set_header Connection "keep-alive"; | |
proxy_store off; | |
proxy_pass http://${ID}/\$ndpath\$is_args\$args; | |
gzip on; | |
gzip_proxied any; | |
gzip_types *; | |
} | |
} | |
} | |
EOF | |
### CONFIGURE NETDATA | |
cp ${INSTALLDIR}/netdata-build/netdata/etc/netdata/netdata.conf ${INSTALLDIR}/netdata-build/netdata/etc/netdata/netdata.conf.backup | |
cat > ${INSTALLDIR}/netdata-build/netdata/etc/netdata/netdata.conf << EOF | |
[web] | |
allow connections from = localhost | |
EOF | |
## START NETDATA | |
export LD_LIBRARY_PATH=${INSTALLDIR}/libuv-build/lib/ | |
${INSTALLDIR}/netdata-build/netdata/usr/sbin/netdata | |
## START NGINX | |
${INSTALLDIR}/nginx-build/sbin/nginx | |
# TO RELOAD (ignore this): | |
# ${INSTALLDIR}/nginx-build/sbin/nginx -s reload | |
echo "Check: http://$(dig +short myip.opendns.com @resolver1.opendns.com):8080/${ID}" | |
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
#user nobody; | |
worker_processes 1; | |
#error_log logs/error.log; | |
#error_log logs/error.log notice; | |
#error_log logs/error.log info; | |
#pid logs/nginx.pid; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
include mime.types; | |
#include sites-enabled/*; | |
default_type application/octet-stream; | |
#log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | |
# '$status $body_bytes_sent "$http_referer" ' | |
# '"$http_user_agent" "$http_x_forwarded_for"'; | |
#access_log logs/access.log main; | |
sendfile on; | |
#tcp_nopush on; | |
#keepalive_timeout 0; | |
keepalive_timeout 65; | |
#gzip on; | |
upstream mitsaklas { | |
server 127.0.0.1:19999; | |
keepalive 64; | |
} | |
server { | |
listen 8080; | |
# the virtual host name of this subfolder should be exposed | |
#server_name netdata.example.com; | |
location = /mitsaklas { | |
return 301 /mitsaklas/; | |
} | |
location ~ /mitsaklas/(?<ndpath>.*) { | |
proxy_redirect off; | |
proxy_set_header Host $host; | |
proxy_set_header X-Forwarded-Host $host; | |
proxy_set_header X-Forwarded-Server $host; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_http_version 1.1; | |
proxy_pass_request_headers on; | |
proxy_set_header Connection "keep-alive"; | |
proxy_store off; | |
proxy_pass http://mitsaklas/$ndpath$is_args$args; | |
gzip on; | |
gzip_proxied any; | |
gzip_types *; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment