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 | e1cf854 | 2017-03-17 18:37:09 +0400 | [diff] [blame] | 3 | {%- from "devops_portal/map.jinja" import service_endpoint with context -%} |
Ilya Kharin | 9954eaf | 2017-03-06 15:21:07 +0400 | [diff] [blame] | 4 | daemon off; |
| 5 | |
| 6 | worker_processes 1; |
| 7 | |
| 8 | error_log /dev/stderr; |
| 9 | pid /var/run/nginx/nginx.pid; |
| 10 | |
| 11 | events { |
| 12 | worker_connections 1024; |
| 13 | } |
| 14 | |
| 15 | http { |
| 16 | include /etc/nginx/mime.types; |
| 17 | |
| 18 | sendfile on; |
| 19 | |
| 20 | access_log /dev/stdout; |
| 21 | |
| 22 | server { |
Ilya Kharin | c27499c | 2017-03-14 16:52:59 +0400 | [diff] [blame] | 23 | listen 0.0.0.0:8000 default_server; |
Ilya Kharin | 9954eaf | 2017-03-06 15:21:07 +0400 | [diff] [blame] | 24 | |
| 25 | root /opt/devops-portal/; |
| 26 | |
| 27 | gzip on; |
| 28 | gzip_min_length 1000; |
| 29 | gzip_types |
| 30 | text/plain |
| 31 | text/css |
| 32 | application/json |
| 33 | application/javascript |
| 34 | application/x-javascript; |
| 35 | |
| 36 | location / { |
Ilya Kharin | b5a5a92 | 2017-03-16 11:59:59 +0400 | [diff] [blame] | 37 | if ($request_method = OPTIONS ) { |
| 38 | add_header Content-Length 0; |
| 39 | add_header Content-Type text/plain; |
| 40 | return 200; |
| 41 | } |
Ilya Kharin | 9954eaf | 2017-03-06 15:21:07 +0400 | [diff] [blame] | 42 | try_files $uri /index.html; |
| 43 | } |
| 44 | |
| 45 | {%- for service_name in services %} |
Ilya Kharin | 918686b | 2017-03-16 20:09:13 +0400 | [diff] [blame] | 46 | {%- if config.service[service_name] is defined %} |
| 47 | {%- set service = config.service[service_name] %} |
Ilya Kharin | 3ce0cd1 | 2017-03-17 18:49:45 +0400 | [diff] [blame^] | 48 | {%- if service.enabled|default(True) and service.configure_proxy|default(False) %} |
Ilya Kharin | 9954eaf | 2017-03-06 15:21:07 +0400 | [diff] [blame] | 49 | |
| 50 | location /api/{{ service_name }} { |
Ilya Kharin | e1cf854 | 2017-03-17 18:37:09 +0400 | [diff] [blame] | 51 | proxy_pass {{ service_url(service.endpoint) }}; |
Ilya Kharin | 9954eaf | 2017-03-06 15:21:07 +0400 | [diff] [blame] | 52 | } |
| 53 | {%- endif %} |
Ilya Kharin | d80a6f6 | 2017-03-15 12:40:36 +0400 | [diff] [blame] | 54 | {%- endif %} |
Ilya Kharin | 9954eaf | 2017-03-06 15:21:07 +0400 | [diff] [blame] | 55 | {%- endfor %} |
| 56 | } |
| 57 | } |