Ilya Kharin | fd293c4 | 2017-03-14 17:34:12 +0400 | [diff] [blame] | 1 | {%- from "devops_portal/map.jinja" import config with context -%} |
Ilya Kharin | 9954eaf | 2017-03-06 15:21:07 +0400 | [diff] [blame] | 2 | {%- from "devops_portal/map.jinja" import services with context -%} |
Ilya Kharin | 5f5d352 | 2017-03-22 23:53:06 +0400 | [diff] [blame] | 3 | {%- from "devops_portal/map.jinja" import service_url with context -%} |
Volodymyr Stoiko | 9c9a6fa | 2017-08-14 13:41:48 +0300 | [diff] [blame] | 4 | {%- from "devops_portal/map.jinja" import service_url_dns with context -%} |
Ilya Kharin | 9954eaf | 2017-03-06 15:21:07 +0400 | [diff] [blame] | 5 | daemon off; |
| 6 | |
| 7 | worker_processes 1; |
| 8 | |
| 9 | error_log /dev/stderr; |
| 10 | pid /var/run/nginx/nginx.pid; |
| 11 | |
| 12 | events { |
| 13 | worker_connections 1024; |
| 14 | } |
| 15 | |
| 16 | http { |
| 17 | include /etc/nginx/mime.types; |
| 18 | |
| 19 | sendfile on; |
| 20 | |
Volodymyr Stoiko | 9c9a6fa | 2017-08-14 13:41:48 +0300 | [diff] [blame] | 21 | 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 Kharin | 9954eaf | 2017-03-06 15:21:07 +0400 | [diff] [blame] | 24 | |
| 25 | server { |
Ilya Kharin | c27499c | 2017-03-14 16:52:59 +0400 | [diff] [blame] | 26 | listen 0.0.0.0:8000 default_server; |
Ilya Kharin | 9954eaf | 2017-03-06 15:21:07 +0400 | [diff] [blame] | 27 | |
| 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 Kharin | b5a5a92 | 2017-03-16 11:59:59 +0400 | [diff] [blame] | 40 | if ($request_method = OPTIONS ) { |
| 41 | add_header Content-Length 0; |
| 42 | add_header Content-Type text/plain; |
| 43 | return 200; |
| 44 | } |
Ilya Kharin | 9954eaf | 2017-03-06 15:21:07 +0400 | [diff] [blame] | 45 | try_files $uri /index.html; |
| 46 | } |
| 47 | |
| 48 | {%- for service_name in services %} |
Ilya Kharin | 918686b | 2017-03-16 20:09:13 +0400 | [diff] [blame] | 49 | {%- if config.service[service_name] is defined %} |
| 50 | {%- set service = config.service[service_name] %} |
Ilya Kharin | 3ce0cd1 | 2017-03-17 18:49:45 +0400 | [diff] [blame] | 51 | {%- if service.enabled|default(True) and service.configure_proxy|default(False) %} |
Volodymyr Stoiko | 9c9a6fa | 2017-08-14 13:41:48 +0300 | [diff] [blame] | 52 | {%- 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 Naumov | 17b957b | 2017-09-22 15:37:48 +0300 | [diff] [blame] | 57 | 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 Stoiko | 9c9a6fa | 2017-08-14 13:41:48 +0300 | [diff] [blame] | 62 | } |
| 63 | {%- else %} |
Ilya Kharin | d3779d5 | 2017-03-30 00:48:36 +0400 | [diff] [blame] | 64 | location /api/{{ service_name }}/ { |
Vladislav Naumov | 17b957b | 2017-09-22 15:37:48 +0300 | [diff] [blame] | 65 | 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 Kharin | 9954eaf | 2017-03-06 15:21:07 +0400 | [diff] [blame] | 70 | } |
| 71 | {%- endif %} |
Ilya Kharin | d80a6f6 | 2017-03-15 12:40:36 +0400 | [diff] [blame] | 72 | {%- endif %} |
Volodymyr Stoiko | 9c9a6fa | 2017-08-14 13:41:48 +0300 | [diff] [blame] | 73 | {%- endif %} |
Ilya Kharin | 9954eaf | 2017-03-06 15:21:07 +0400 | [diff] [blame] | 74 | {%- endfor %} |
| 75 | } |
| 76 | } |