blob: 20b67781ed37dd3497ed7e665f41c91ac157fc9b [file] [log] [blame]
Ilya Kharinfd293c42017-03-14 17:34:12 +04001{%- from "devops_portal/map.jinja" import config with context -%}
Ilya Kharin9954eaf2017-03-06 15:21:07 +04002{%- from "devops_portal/map.jinja" import services with context -%}
Ilya Kharin5f5d3522017-03-22 23:53:06 +04003{%- from "devops_portal/map.jinja" import service_url with context -%}
Volodymyr Stoiko9c9a6fa2017-08-14 13:41:48 +03004{%- from "devops_portal/map.jinja" import service_url_dns with context -%}
Ilya Kharin9954eaf2017-03-06 15:21:07 +04005daemon off;
6
7worker_processes 1;
8
9error_log /dev/stderr;
10pid /var/run/nginx/nginx.pid;
11
12events {
13 worker_connections 1024;
14}
15
16http {
17 include /etc/nginx/mime.types;
18
19 sendfile on;
20
Volodymyr Stoiko9c9a6fa2017-08-14 13:41:48 +030021 log_format upstreamlog '[$time_local] $remote_addr - $remote_user - $server_name to: $upstream_addr: $request upstream_response_time $upstream_response_time msec $msec request_time $request_time';
22
23 access_log /dev/stdout upstreamlog;
Ilya Kharin9954eaf2017-03-06 15:21:07 +040024
25 server {
Ilya Kharinc27499c2017-03-14 16:52:59 +040026 listen 0.0.0.0:8000 default_server;
Ilya Kharin9954eaf2017-03-06 15:21:07 +040027
28 root /opt/devops-portal/;
29
30 gzip on;
31 gzip_min_length 1000;
32 gzip_types
33 text/plain
34 text/css
35 application/json
36 application/javascript
37 application/x-javascript;
38
39 location / {
Ilya Kharinb5a5a922017-03-16 11:59:59 +040040 if ($request_method = OPTIONS ) {
41 add_header Content-Length 0;
42 add_header Content-Type text/plain;
43 return 200;
44 }
Ilya Kharin9954eaf2017-03-06 15:21:07 +040045 try_files $uri /index.html;
46 }
47
48{%- for service_name in services %}
Ilya Kharin918686b2017-03-16 20:09:13 +040049{%- if config.service[service_name] is defined %}
50{%- set service = config.service[service_name] %}
Ilya Kharin3ce0cd12017-03-17 18:49:45 +040051{%- if service.enabled|default(True) and service.configure_proxy|default(False) %}
Volodymyr Stoiko9c9a6fa2017-08-14 13:41:48 +030052{%- if service.resolve_hostname|default(False) %}
53 location /api/{{ service_name }}/ {
54 resolver 127.0.0.11;
55 set ${{ service.endpoint.address|replace("-", "_") }} {{ service.endpoint.address }};
56 rewrite ^/api/{{ service_name }}/(.*) /$1 break;
Vladislav Naumov17b957b2017-09-22 15:37:48 +030057 proxy_connect_timeout {{ service.proxy_connect_timeout|default(300) }};
58 proxy_send_timeout {{ service.proxy_send_timeout|default(300) }};
59 proxy_read_timeout {{ service.proxy_read_timeout|default(300) }};
60 send_timeout {{ service.send_timeout|default(300) }};
61 proxy_pass {{ service_url_dns(service.endpoint) }};
Volodymyr Stoiko9c9a6fa2017-08-14 13:41:48 +030062 }
63{%- else %}
Ilya Kharind3779d52017-03-30 00:48:36 +040064 location /api/{{ service_name }}/ {
Vladislav Naumov17b957b2017-09-22 15:37:48 +030065 proxy_connect_timeout {{ service.proxy_connect_timeout|default(300) }};
66 proxy_send_timeout {{ service.proxy_send_timeout|default(300) }};
67 proxy_read_timeout {{ service.proxy_read_timeout|default(300) }};
68 send_timeout {{ service.send_timeout|default(300) }};
69 proxy_pass {{ service_url(service.endpoint) }};
Ilya Kharin9954eaf2017-03-06 15:21:07 +040070 }
71{%- endif %}
Ilya Kharind80a6f62017-03-15 12:40:36 +040072{%- endif %}
Volodymyr Stoiko9c9a6fa2017-08-14 13:41:48 +030073{%- endif %}
Ilya Kharin9954eaf2017-03-06 15:21:07 +040074{%- endfor %}
75 }
76}