| {%- from "devops_portal/map.jinja" import config with context -%} |
| {%- from "devops_portal/map.jinja" import services with context -%} |
| {%- from "devops_portal/map.jinja" import service_url with context -%} |
| {%- from "devops_portal/map.jinja" import service_url_dns with context -%} |
| daemon off; |
| |
| worker_processes 1; |
| |
| error_log /dev/stderr; |
| pid /var/run/nginx/nginx.pid; |
| |
| events { |
| worker_connections 1024; |
| } |
| |
| http { |
| include /etc/nginx/mime.types; |
| |
| sendfile on; |
| |
| 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'; |
| |
| access_log /dev/stdout upstreamlog; |
| |
| server { |
| listen 0.0.0.0:8000 default_server; |
| |
| root /opt/devops-portal/; |
| |
| gzip on; |
| gzip_min_length 1000; |
| gzip_types |
| text/plain |
| text/css |
| application/json |
| application/javascript |
| application/x-javascript; |
| |
| location / { |
| if ($request_method = OPTIONS ) { |
| add_header Content-Length 0; |
| add_header Content-Type text/plain; |
| return 200; |
| } |
| try_files $uri /index.html; |
| } |
| |
| {%- for service_name in services %} |
| {%- if config.service[service_name] is defined %} |
| {%- set service = config.service[service_name] %} |
| {%- if service.enabled|default(True) and service.configure_proxy|default(False) %} |
| {%- if service.resolve_hostname|default(False) %} |
| location /api/{{ service_name }}/ { |
| resolver 127.0.0.11; |
| set ${{ service.endpoint.address|replace("-", "_") }} {{ service.endpoint.address }}; |
| rewrite ^/api/{{ service_name }}/(.*) /$1 break; |
| proxy_connect_timeout {{ service.proxy_connect_timeout|default(300) }}; |
| proxy_send_timeout {{ service.proxy_send_timeout|default(300) }}; |
| proxy_read_timeout {{ service.proxy_read_timeout|default(300) }}; |
| send_timeout {{ service.send_timeout|default(300) }}; |
| proxy_pass {{ service_url_dns(service.endpoint) }}; |
| } |
| {%- else %} |
| location /api/{{ service_name }}/ { |
| proxy_connect_timeout {{ service.proxy_connect_timeout|default(300) }}; |
| proxy_send_timeout {{ service.proxy_send_timeout|default(300) }}; |
| proxy_read_timeout {{ service.proxy_read_timeout|default(300) }}; |
| send_timeout {{ service.send_timeout|default(300) }}; |
| proxy_pass {{ service_url(service.endpoint) }}; |
| } |
| {%- endif %} |
| {%- endif %} |
| {%- endif %} |
| {%- endfor %} |
| } |
| } |