# Transparent proxy which passes requests to a set of un-pooled # application servers that are reserved for debugging, based on # the value of the X-Wikimedia-Debug header. # The X-Wikimedia-Debug header is made up of semicolon-separated # fields. Each field may consist of either an attribute name or # an attribute=value pairs. The block below extracts the value of # the 'backend' attribute. For backward-compatibility, if the # header does not contain a well-formed 'backend' attribute, then # the entire header is used as the backend value. map_hash_bucket_size 128; # Trims the content of X-Wikimedia-Debug to be just the first flag map $http_x_wikimedia_debug $debug_backend { "~backend=(?[^;]+)" $h; default $http_x_wikimedia_debug; } # Checks if php7 is selected map $http_x_wikimedia_debug $php_engine { "~; php7" "php7"; default "hhvm"; } map $debug_backend $debug_host { "~^((mwdebug1001|mwdebug1002)\\.eqiad\\.wmnet|(mwdebug2001|mwdebug2002)\\.codfw\\.wmnet)" $debug_backend; "1" "mwdebug1001.eqiad.wmnet"; "mw1017.eqiad.wmnet" "mwdebug1001.eqiad.wmnet"; "mw1099.eqiad.wmnet" "mwdebug1002.eqiad.wmnet"; "mw2017.codfw.wmnet" "mwdebug2001.codfw.wmnet"; "mw2099.codfw.wmnet" "mwdebug2002.codfw.wmnet"; default 'invalid'; } server { listen [::]:80 ipv6only=off; server_name _; access_log /var/log/nginx/debug_proxy_access.log; error_log /var/log/nginx/debug_proxy_error.log; client_max_body_size 100m; resolver 10.3.0.1; location / { if ($debug_host = invalid) { return 400; } proxy_buffering off; proxy_pass $scheme://$debug_host; proxy_pass_request_headers on; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # Swap whatever cookie we had for PHP_ENGINE with what we extracted set_by_lua_block $cookies { local cookie_snippet_to_set = "PHP_ENGINE=" .. ngx.var.php_engine; local current_engine = ngx.var.cookie_PHP_ENGINE; if (ngx.var.http_cookie == nil) then return cookie_snippet_to_set; elseif (current_engine == nil) then return ngx.var.http_cookie .. ";" .. cookie_snippet_to_set; else local php_engine_cookie = "PHP_ENGINE=" .. current_engine; return string.gsub(ngx.var.http_cookie, php_engine_cookie, cookie_snippet_to_set); end } proxy_http_version 1.1; proxy_set_header Cookie $cookies; proxy_set_header Host $host; proxy_pass_header Server; proxy_read_timeout 180s; } }