Skip to content

Commit

Permalink
Merge pull request #45 from HSLdevcom/ext-proxy
Browse files Browse the repository at this point in the history
Ext proxy
  • Loading branch information
vesameskanen authored Aug 31, 2017
2 parents dd5f7bf + cb0c8b7 commit 426c0a3
Show file tree
Hide file tree
Showing 8 changed files with 663 additions and 308 deletions.
12 changes: 5 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
FROM nginx
FROM nginx:1.13-alpine
MAINTAINER Reittiopas version: 0.1
ENV INSTALL_DIR="/opt/nginx"

WORKDIR /etc/nginx

RUN mkdir -p $INSTALL_DIR /opt/nginx/www /opt/nginx/cache /opt/nginx/geocache /opt/nginx/temp-cache /opt/nginx/cache/temp /var/cache/nginx/client_temp /var/cache/nginx/fastcgi_temp/ /var/cache/nginx/uwsgi_temp /var/cache/nginx/scgi_temp

ADD index.html /opt/nginx/www/
ADD nginx.conf /etc/nginx/nginx.conf
ADD common.conf /etc/nginx/common.conf
ADD legacy-redirects.conf /etc/nginx/legacy-redirects.conf
ADD *.conf /etc/nginx/

RUN rm /var/log/nginx/* && chmod -R a+rwX ${INSTALL_DIR} /etc/nginx/ /var/log/nginx/ /var/cache/nginx/ /var/run/
#USER 9999

#because we dont want to use disk on the containers for logs

RUN ln -sf /dev/stdout /var/log/nginx/access.log
RUN ln -sf /dev/stderr /var/log/nginx/error.log


WORKDIR /etc/nginx
EXPOSE 8080

ADD run.sh /usr/local/bin/
Expand Down
57 changes: 57 additions & 0 deletions common.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ location /geocoding/v1/ {
proxy_cache geocoding;
proxy_cache_valid 3d;
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
add_header X-Proxy-Cache $upstream_cache_status;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Expand All @@ -17,6 +18,13 @@ location /realtime/siri2gtfsrt/v1/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
proxy_cache common;
proxy_cache_valid 200 30s;
proxy_cache_lock on;
proxy_cache_key "$host$request_uri";
add_header X-Proxy-Cache $upstream_cache_status;
proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie;
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
}

#"alias" for siri2gtfsrt
Expand All @@ -27,6 +35,13 @@ location /realtime/trip-updates/v1/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
proxy_cache common;
proxy_cache_valid 200 30s;
proxy_cache_lock on;
proxy_cache_key "$host$request_uri";
add_header X-Proxy-Cache $upstream_cache_status;
proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie;
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
}

location /realtime/hslalert/v1/ {
Expand All @@ -36,6 +51,13 @@ location /realtime/hslalert/v1/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
proxy_cache common;
proxy_cache_valid 200 30s;
proxy_cache_lock on;
proxy_cache_key "$host$request_uri";
add_header X-Proxy-Cache $upstream_cache_status;
proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie;
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
}

#"alias" for hslalert
Expand All @@ -46,6 +68,13 @@ location /realtime/service-alerts/v1/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
proxy_cache common;
proxy_cache_valid 200 30s;
proxy_cache_lock on;
proxy_cache_key "$host$request_uri";
add_header X-Proxy-Cache $upstream_cache_status;
proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie;
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
}

location /realtime/navigator-server/v1/ {
Expand All @@ -55,6 +84,13 @@ location /realtime/navigator-server/v1/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
proxy_cache common;
proxy_cache_valid 200 30s;
proxy_cache_lock on;
proxy_cache_key "$host$request_uri";
add_header X-Proxy-Cache $upstream_cache_status;
proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie;
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
}

#"alias" for navigator-server
Expand All @@ -65,6 +101,13 @@ location /realtime/vehicle-positions/v1/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
proxy_cache common;
proxy_cache_valid 200 30s;
proxy_cache_lock on;
proxy_cache_key "$host$request_uri";
add_header X-Proxy-Cache $upstream_cache_status;
proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie;
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
}

#"alias" for navigator-service
Expand All @@ -75,6 +118,13 @@ location /realtime/mqtt-cache/v1/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
proxy_cache common;
proxy_cache_valid 200 30s;
proxy_cache_lock on;
proxy_cache_key "$host$request_uri";
add_header X-Proxy-Cache $upstream_cache_status;
proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie;
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
}

location /realtime/raildigitraffic2gtfsrt/v1/ {
Expand All @@ -85,6 +135,13 @@ location /realtime/raildigitraffic2gtfsrt/v1/ {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host;
add_header Access-Control-Allow-Origin *;
proxy_cache common;
proxy_cache_valid 200 30s;
proxy_cache_lock on;
proxy_cache_key "$host$request_uri";
add_header X-Proxy-Cache $upstream_cache_status;
proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie;
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
}

location /map/v1/ {
Expand Down
55 changes: 55 additions & 0 deletions external.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#smoove citybike api (http://helsinki-fi.smoove.pro/api-public/stations)
location /out/helsinki-fi.smoove.pro/ {
proxy_pass http://helsinki-fi.smoove.pro/;
allow 172.17.0.0/16;
allow 10.32.0.0/16;
deny all;
proxy_cache ext_cache;
proxy_cache_valid 200 30s;
proxy_cache_lock on;
add_header X-Proxy-Cache $upstream_cache_status;
proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie;
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
}

#hsl park api https://p.hsl.fi/api/v1/facilities.json?limit=-1
location /out/p.hsl.fi/ {
proxy_pass https://p.hsl.fi/;
allow 172.17.0.0/16;
allow 10.32.0.0/16;
deny all;
proxy_cache ext_cache;
proxy_cache_valid 200 30s;
proxy_cache_lock on;
add_header X-Proxy-Cache $upstream_cache_status;
proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie;
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
}

#oulu realtime api (http://92.62.36.215/RTIX/trip-update)
location /out/92.62.36.215/ {
proxy_pass http://92.62.36.215/;
allow 172.17.0.0/16;
allow 10.32.0.0/16;
deny all;
proxy_cache ext_cache;
proxy_cache_valid 200 30s;
proxy_cache_lock on;
add_header X-Proxy-Cache $upstream_cache_status;
proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie;
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
}

#livi gtfs rt (http://beta.liikennevirasto.fi/joukkoliikenne/manual_gtfsrt/api/gtfsrt/alerts)
location /out/beta.liikennevirasto.fi/ {
proxy_pass https://beta.liikennevirasto.fi/;
allow 172.17.0.0/16;
allow 10.32.0.0/16;
deny all;
proxy_cache ext_cache;
proxy_cache_valid 200 30s;
proxy_cache_lock on;
add_header X-Proxy-Cache $upstream_cache_status;
proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie;
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
}
13 changes: 13 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ daemon off;

http {

log_format custom '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_user_agent" $host $request_time';

access_log /var/log/nginx/access.log custom;

sendfile on;

gzip on;
Expand All @@ -29,6 +35,9 @@ http {
proxy_temp_path /opt/nginx/temp-cache;
proxy_cache_path /opt/nginx/cache levels=1:2 keys_zone=tiles:10m max_size=4g inactive=7d use_temp_path=off;
proxy_cache_path /opt/nginx/geocache levels=1:2 keys_zone=geocoding:10m max_size=4g inactive=7d use_temp_path=off;
proxy_cache_path /opt/nginx/external-cache levels=1:2 keys_zone=ext_cache:10m max_size=1g inactive=60m use_temp_path=off;
proxy_cache_path /opt/nginx/common levels=1:2 keys_zone=common:10m max_size=4g inactive=60m use_temp_path=off;


# API endpoints
# These domains handle only api calls, not UI
Expand All @@ -45,8 +54,12 @@ http {
"";

listen 8080;
proxy_connect_timeout 10s;
proxy_send_timeout 10s;
proxy_read_timeout 20s;
include common.conf;
include legacy-redirects.conf;
include external.conf;

# Health check
location / {
Expand Down
7 changes: 3 additions & 4 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/bin/bash
#!/bin/ash

#workaround for azure DNS issue

if [ "$EUID" -eq 0 ]
then echo "search marathon.l4lb.thisdcos.directory" >> /etc/resolv.conf
if [ -n "$MESOS_CONTAINER_NAME" ]; then
echo "search marathon.l4lb.thisdcos.directory" >> /etc/resolv.conf;
fi

#start nginx
Expand Down
Loading

0 comments on commit 426c0a3

Please sign in to comment.