<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
      <template id="runbot.nginx_config">
pid <t t-out="nginx_dir"/>/nginx.pid;
error_log <t t-out="nginx_dir"/>/error.log;
worker_processes  1;
events { worker_connections  1024; }
http {
charset utf-8;
include /etc/nginx/mime.types;
server_names_hash_max_size 512;
server_names_hash_bucket_size 256;
client_max_body_size 64M;
index index.html;
log_format full '$remote_addr - $remote_user [$time_local] '
                '"$request" $status $body_bytes_sent '
                '"$http_referer" "$http_user_agent" $request_time';
access_log <t t-out="nginx_dir"/>/access.log full;
error_log <t t-out="nginx_dir"/>/error.log;
client_body_temp_path <t t-out="nginx_dir"/>;
fastcgi_temp_path <t t-out="nginx_dir"/>;

autoindex on;

gzip on;
gzip_types text/css text/plain application/xml application/json application/javascript;

charset_types text/plain;

map $http_x_forwarded_proto $real_scheme {
  default $http_x_forwarded_proto;
  ''      $scheme;
}

proxy_temp_path <t t-out="nginx_dir"/>;
proxy_read_timeout 600;
proxy_connect_timeout 600;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Proto $real_scheme;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For 127.0.0.42;
proxy_set_header X-Real-IP 127.0.0.42;

server {
    listen 8080 default;
    location /runbot/static/ {
      alias <t t-out="runbot_static"/>;
      autoindex off;
      return 404;
      location /runbot/static/src { }
      location ~ /runbot/static/build/[^/]+/(logs|tests|coverage)/ {
          autoindex on;
          add_header 'Access-Control-Allow-Origin' '<t t-out="base_url"/>';
      }
    }
}

server {
  listen 8080;
  server_name ~^dockerhub\.<t t-out="re_escape(host_name)"/>$;

	location /v2/ {
		limit_except GET HEAD OPTIONS {
		    deny all;
		}
		proxy_pass http://localhost:5001;
    proxy_set_header  Host               $http_host;
    proxy_set_header  X-Real-IP          $remote_addr;
    proxy_set_header  X-Forwarded-For    $proxy_add_x_forwarded_for;
    proxy_set_header  X-Forwarded-Proto  $scheme;
    proxy_read_timeout                   900;
	}
}

<t id="root_anchor"/>

<t t-foreach="builds" t-as="build">
<t id="server_build_anchor"/>
server {
  listen 8080;
  server_name ~^<t t-out="re_escape(build.dest)"/>(-[a-z0-9_-]+)?-<t t-out="build._get_run_token()[0]"/>(-[a-z0-9_]+)\.<t t-out="re_escape(build.host)"/>$;
  <t id="build_anchor_authenticated"/>
  location / {
    <t id="build_anchor_authenticated_side_effect"/>
    return 307 http://<t t-out="build.dest"/>$1.<t t-out="build.host"/>;
  }
}

server {
    listen 8080;
    server_name ~^<t t-out="re_escape(build.dest)"/>(-[a-z0-9_-]+)?\.<t t-out="re_escape(build.host)"/>$;
    <t id="build_anchor"/>
    location / { proxy_pass http://127.0.0.1:<t t-out="build.port"/>; }
    location /longpolling { proxy_pass http://127.0.0.1:<t t-out="build.port + 1"/>; }
    location /websocket {
      proxy_pass http://127.0.0.1:<t t-out="build.port + 1"/>;
      proxy_set_header X-Forwarded-Host $host;
      proxy_set_header X-Forwarded-Proto $real_scheme;
      proxy_set_header Host $host;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "Upgrade";
      proxy_set_header X-Forwarded-For 127.0.0.42;
      proxy_set_header X-Real-IP     127.0.0.42;

    }
}
</t>
server {
    listen 8080;
    server_name ~.+\.<t t-out="re_escape(host_name)"/>$;
    location / { return 404; }
}
}
      </template>
    </data>
</odoo>
