sub write_nginx_test_config()

in lib/ES/Util.pm [488:583]


sub write_nginx_test_config {
#===================================
    my ( $dest, $docs_dir, $redirects_file, $watching_web, $preview_enabled ) = @_;

    my $redirects_line = $redirects_file ? "include $redirects_file;\n" : '';
    my $web_conf;
    if ( $watching_web ) {
        $web_conf = <<"CONF"
    rewrite ^/guide/static/docs-v1\\.js(.*)\$ /guide/static/docs_js/index-v1.js\$1 last;
    location ^~ /guide/static/jquery.js {
      alias /node_modules/jquery/dist/jquery.js;
      types {
        application/javascript js;
      }
    }
    location ^~ /guide/static/ {
      proxy_pass http://0.0.0.0:1234;
    }
CONF
    } else {
        $web_conf = '';
    }

    my $guide_conf;
    if ( $preview_enabled ) {
        $guide_conf = <<"CONF"
    location ~/(guide|diff) {
      proxy_pass http://0.0.0.0:3000;
      proxy_http_version 1.1;
      proxy_set_header Host \$host;
      proxy_cache_bypass \$http_upgrade;
      proxy_buffering off;
      gzip on;
      add_header 'Access-Control-Allow-Origin' '*';
      if (\$request_method = 'OPTIONS') {
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'kbn-xsrf-token';
      }
    }
CONF
    } else {
        $guide_conf = <<"CONF"
    location /guide {
      alias $docs_dir;
      add_header 'Access-Control-Allow-Origin' '*';
      if (\$request_method = 'OPTIONS') {
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'kbn-xsrf-token';
      }
    }
CONF
    }

    my $nginx_conf = <<"CONF";
daemon off;
error_log /dev/stdout info;
pid /run/nginx/nginx.pid;

events {
  worker_connections 64;
}

http {
  error_log /dev/stdout crit;
  log_format short '[\$time_local] "\$request" \$status';
  access_log /dev/stdout short;

  server {
    listen 8000;
    location = / {
      return 301 /guide/index.html;
    }
$web_conf
$guide_conf
    location / {
      alias /docs_build/resources/web/static/;
      autoindex off;
    }
    types {
      application/javascript js;
      image/gif gif;
      image/jpeg jpg;
      image/jpeg jpeg;
      image/svg+xml svg;
      text/css css;
      text/html html;
    }
    rewrite ^/assets/(.+)\$ https://www.elastic.co/assets/\$1 permanent;
    rewrite ^/gdpr-data\$ https://www.elastic.co/gdpr-data permanent;
    rewrite ^/static/(.+)\$ https://www.elastic.co/static/\$1 permanent;
$redirects_line
  }
}
CONF
    $dest->spew( iomode => '>:utf8', $nginx_conf );
}