Skip to content

Commit eff92a2

Browse files
authored
Merge pull request #436 from ocf/internal-nginx
Add nginx proxy layer to protect /metrics
2 parents 771a500 + 68de88f commit eff92a2

File tree

11 files changed

+53
-3
lines changed

11 files changed

+53
-3
lines changed

Dockerfile.static.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ RUN mkdir /opt/ocfweb/static
66
ENV OCFWEB_STATIC_ROOT /opt/ocfweb/static
77
RUN /opt/ocfweb/venv/bin/python /opt/ocfweb/manage.py collectstatic --noinput
88

9-
COPY services/nginx /opt/ocfweb/services/nginx
9+
COPY services/static /opt/ocfweb/services/static
1010
RUN chown -R nobody:nogroup /opt/ocfweb/services
1111

1212
USER nobody

Dockerfile.web.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM {tag}
22

3-
COPY services/web /opt/ocfweb/services/web
3+
COPY services/web /opt/ocfweb/services/
44
RUN chown -R nobody:nogroup /opt/ocfweb/services
55

66
USER nobody

conf/metrics.htpasswd

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Empty password
2+
prometheus:$apr1$4CUVWyim$MGnAdRap1gqM1estPDAPK0
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

services/web/run renamed to services/web/app/run

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ exec 2>&1
44

55
cd /opt/ocfweb
66
exec /opt/ocfweb/venv/bin/gunicorn \
7-
-b 0.0.0.0:8000 \
7+
-b 127.0.0.1:8080 \
88
-w 4 \
99
ocfweb.wsgi

services/web/nginx/log/run

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
exec /opt/share/utils/sbin/stdin2syslog ocfweb-web-nginx

services/web/nginx/nginx.conf

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
error_log /dev/stderr;
2+
daemon off;
3+
pid /tmp/nginx_pid;
4+
5+
events {}
6+
7+
http {
8+
include /etc/nginx/mime.types;
9+
access_log /dev/stderr;
10+
11+
upstream ocfweb {
12+
server 127.0.0.1:8080;
13+
}
14+
15+
server {
16+
listen 8000;
17+
18+
client_body_temp_path /tmp/nginx_client_temp;
19+
fastcgi_temp_path /tmp/nginx_fastcgi_temp;
20+
proxy_temp_path /tmp/nginx_proxy_temp;
21+
scgi_temp_path /tmp/nginx_scgi_temp;
22+
uwsgi_temp_path /tmp/nginx_uwsgi_temp;
23+
24+
location /metrics {
25+
proxy_pass http://ocfweb;
26+
proxy_set_header Host www.ocf.berkeley.edu;
27+
28+
auth_basic "Metrics";
29+
auth_basic_user_file /etc/ocfweb/metrics.htpasswd;
30+
}
31+
32+
location / {
33+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
34+
proxy_set_header X-Forwarded-Proto $scheme;
35+
proxy_set_header Host $http_host;
36+
proxy_redirect off;
37+
proxy_pass http://ocfweb;
38+
}
39+
}
40+
}

services/web/nginx/run

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
exec 2>&1
4+
5+
exec nginx -c nginx.conf -p $(pwd)

0 commit comments

Comments
 (0)