<commit_before>keepalive_timeout 120;

proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;

# This sets the IP used by Nginx to the client IP from the X-Forwarded-For
# chain, rather than the IP from the CDN node
real_ip_header X-Forwarded-For;
real_ip_recursive on;
set_real_ip_from 0.0.0.0/0;

# With the above real-ip in place we can limit connections and requests
# based on that
limit_req zone=rate burst=5 nodelay;
limit_conn connections 4;

proxy_read_timeout 10;

access_log /var/log/nginx/lb-access.log timed_combined;
error_log  /var/log/nginx/lb-error.log;

<%- if @platform != 'production' -%>
deny all;
auth_basic            "Enter your bet<PASSWORD>mo password";
auth_basic_user_file  /etc/govuk.htpasswd;
satisfy any;
<%- end -%>

# These redirects are a last resort for any given problem. Any additions should be cleared with Etienne
# They are recorded here as well for those without access to GitHub
# https://docs.google.com/a/digital.cabinet-office.gov.uk/document/d/1DJeKKnhmfQVJWhlwn0M7R5hSFy7t0kz-VJn2FqNSc7Y/edit
rewrite ^/cloudstore/?$ http://gcloud.civilservice.gov.uk/cloudstore/;
rewrite ^/digitalstrategy/?$ http://publications.cabinetoffice.gov.uk/digital/;
rewrite ^/performance/transactional-services/?$ http://transactionalservices.alphagov.co.uk/;
rewrite ^/support/internal/?$ https://support.<%= @app_domain %>/;
rewrite ^/tell-us-once-report-death/?$ /after-a-death redirect;
rewrite ^/studentfinance/?$ /student-finance permanent;
rewrite ^/browse/births-deaths-marriages/registry-offices/?$ /browse/births-deaths-marriages/register-offices permanent;
rewrite ^/jobsearch/?$ /jobs-jobsearch permanent;
rewrite ^/greendeal/?$ /green-deal-energy-saving-measures permanent;
rewrite ^/green-deal/?$ /green-deal-energy-saving-measures permanent;
rewrite ^/child-maintenance/?$ /calculate-child-maintenance permanent;
rewrite ^/childmaintenance/?$ /calculate-child-maintenance permanent;
rewrite ^/growing-a-business/?$ /growing-your-business permanent;

location @upstream {
  proxy_pass http://varnish;
}

location ~ ^/apply-for-a-licence/ {
  proxy_intercept_errors off;

  # Set proxy timeout to 50 seconds as a quick fix for problems
  # where civica QueryPayments calls are taking too long.
  # 50s is max beccause that's what haproxy is configured at
  proxy_read_timeout 50;
  proxy_pass http://varnish;
}

location ~ ^/apply-for-a-licence/assets/ {
  limit_req zone=rate burst=5 nodelay;
  limit_conn connections 25;
  proxy_pass http://varnish;
}

location ~ ^/performance/graphs/ {<commit_msg>Document the three different groups of Rewrites, their purpose and authorisation<commit_after>keepalive_timeout 120;

proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;

# This sets the IP used by Nginx to the client IP from the X-Forwarded-For
# chain, rather than the IP from the CDN node
real_ip_header X-Forwarded-For;
real_ip_recursive on;
set_real_ip_from 0.0.0.0/0;

# With the above real-ip in place we can limit connections and requests
# based on that
limit_req zone=rate burst=5 nodelay;
limit_conn connections 4;

proxy_read_timeout 10;

access_log /var/log/nginx/lb-access.log timed_combined;
error_log  /var/log/nginx/lb-error.log;

<%- if @platform != 'production' -%>
deny all;
auth_basic            "<PASSWORD>";
auth_basic_user_file  /etc/govuk.htpasswd;
satisfy any;
<%- end -%>

# These redirects to external URLs are a last resort for any given problem. Any additions should be cleared with Etienne
# They are recorded here as well for those without access to GitHub
# https://docs.google.com/a/digital.cabinet-office.gov.uk/document/d/1DJeKKnhmfQVJWhlwn0M7R5hSFy7t0kz-VJn2FqNSc7Y/edit
rewrite ^/cloudstore/?$ http://gcloud.civilservice.gov.uk/cloudstore/;
rewrite ^/digitalstrategy/?$ http://publications.cabinetoffice.gov.uk/digital/;
rewrite ^/performance/transactional-services/?$ http://transactionalservices.alphagov.co.uk/;
rewrite ^/support/internal/?$ https://support.<%= @app_domain %>/;

# These rewrites (FURLS) are for the purposes of URL Shortening. As of 2012-11-14 the process for adding this has not yet been clarified. If in doubt, check with your Tech Arch.
rewrite ^/studentfinance/?$ /student-finance permanent;
rewrite ^/jobsearch/?$ /jobs-jobsearch permanent;
rewrite ^/greendeal/?$ /green-deal-energy-saving-measures permanent;
rewrite ^/green-deal/?$ /green-deal-energy-saving-measures permanent;
rewrite ^/child-maintenance/?$ /calculate-child-maintenance permanent;
rewrite ^/childmaintenance/?$ /calculate-child-maintenance permanent;
rewrite ^/growing-a-business/?$ /growing-your-business permanent;

# These rewrites are caused by content being relocated. They should be amended by the person moving the content.
rewrite ^/tell-us-once-report-death/?$ /after-a-death redirect;
rewrite ^/browse/births-deaths-marriages/registry-offices/?$ /browse/births-deaths-marriages/register-offices permanent;

# End rewrites

location @upstream {
  proxy_pass http://varnish;
}

location ~ ^/apply-for-a-licence/ {
  proxy_intercept_errors off;

  # Set proxy timeout to 50 seconds as a quick fix for problems
  # where civica QueryPayments calls are taking too long.
  # 50s is max beccause that's what haproxy is configured at
  proxy_read_timeout 50;
  proxy_pass http://varnish;
}

location ~ ^/apply-for-a-licence/assets/ {
  limit_req zone=rate burst=5 nodelay;
  limit_conn connections 25;
  proxy_pass http://varnish;
}

location ~ ^/performance/graphs/ {
{'fraction_non_alphanumeric': 0.11156882938551321, 'fraction_numerical': 0.01132852729145211, 'mean_word_length': 4.775024777006937, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '355470', 'n_tokens_mistral': 2110, 'n_tokens_neox': 1957, 'n_words': 513}