Skip to content

Commit

Permalink
Merge pull request #1435 from USEPA/nginx-fast-404
Browse files Browse the repository at this point in the history
Nginx fast 404
  • Loading branch information
carsoncho authored Aug 12, 2024
2 parents 9cbff05 + 9e7a76b commit 6e29d91
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 16 deletions.
32 changes: 16 additions & 16 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ build:drupal:
WEBCMS_ENVIRONMENT: preproduction

# Build the FPM metrics sidecar container.
build:metrics:dev:
.build:metrics:dev:
extends: .kaniko
stage: build
rules:
Expand Down Expand Up @@ -385,7 +385,7 @@ build:metrics:dev:
# infrastructure: this typically means that we mirror only on the main and live branches.

# Mirror the AWS CloudWatch agent image using the latest tag.
copy:cloudwatch:dev:
.copy:cloudwatch:dev:
extends: .kaniko
stage: copy
rules:
Expand Down Expand Up @@ -427,7 +427,7 @@ copy:cloudwatch:dev:
WEBCMS_SITE: dev

# Mirror the New Relic PHP daemon
copy:newrelic:dev:
.copy:newrelic:dev:
extends: .kaniko
stage: copy
rules:
Expand Down Expand Up @@ -455,7 +455,7 @@ Drupal:
variables:
GIT_STRATEGY: none
script:
- 'export PRISMA_CI_TOKEN=$(curl -kH "Content-Type: application/json" -d "{\"username\":\"$PRISMA_CI_USERNAME\", \"password\":\"$PRISMA_CI_PASSWORD\"}" https://prismacloud.epa.gov/api/v22.12/authenticate | jq -r .token)'
- 'export PRISMA_CI_TOKEN=$(curl -kH "Content-Type: application/json" -d "{\"username\":\"$PRISMA_CI_USERNAME\", \"password\":\"$PRISMA_CI_PASSWORD\"}" https://prismacloud.epa.gov/api/v32.01/authenticate | jq -r .token)'
- 'curl --progress-bar -L -k --header "Authorization: Bearer $PRISMA_CI_TOKEN" https://prismacloud.epa.gov/api/v1/util/twistcli > twistcli; chmod a+x twistcli;'
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker pull $CI_REGISTRY_IMAGE/webcms-preproduction-dev-drupal:$WEBCMS_IMAGE_TAG
Expand All @@ -472,7 +472,7 @@ Nginx:
variables:
GIT_STRATEGY: none
script:
- 'export PRISMA_CI_TOKEN=$(curl -kH "Content-Type: application/json" -d "{\"username\":\"$PRISMA_CI_USERNAME\", \"password\":\"$PRISMA_CI_PASSWORD\"}" https://prismacloud.epa.gov/api/v22.12/authenticate | jq -r .token)'
- 'export PRISMA_CI_TOKEN=$(curl -kH "Content-Type: application/json" -d "{\"username\":\"$PRISMA_CI_USERNAME\", \"password\":\"$PRISMA_CI_PASSWORD\"}" https://prismacloud.epa.gov/api/v32.01/authenticate | jq -r .token)'
- 'curl --progress-bar -L -k --header "Authorization: Bearer $PRISMA_CI_TOKEN" https://prismacloud.epa.gov/api/v1/util/twistcli > twistcli; chmod a+x twistcli;'
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker pull $CI_REGISTRY_IMAGE/webcms-preproduction-dev-nginx:$WEBCMS_IMAGE_TAG
Expand All @@ -489,10 +489,10 @@ Drush:
variables:
GIT_STRATEGY: none
script:
- 'export PRISMA_CI_TOKEN=$(curl -kH "Content-Type: application/json" -d "{\"username\":\"$PRISMA_CI_USERNAME\", \"password\":\"$PRISMA_CI_PASSWORD\"}" https://prismacloud.epa.gov/api/v22.12/authenticate | jq -r .token)'
- 'export PRISMA_CI_TOKEN=$(curl -kH "Content-Type: application/json" -d "{\"username\":\"$PRISMA_CI_USERNAME\", \"password\":\"$PRISMA_CI_PASSWORD\"}" https://prismacloud.epa.gov/api/v32.01/authenticate | jq -r .token)'
- 'curl --progress-bar -L -k --header "Authorization: Bearer $PRISMA_CI_TOKEN" https://prismacloud.epa.gov/api/v1/util/twistcli > twistcli; chmod a+x twistcli;'
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker pull $CI_REGISTRY_IMAGE/webcms-preproduction-dev-terraform-database:$WEBCMS_IMAGE_TAG
- docker pull $CI_REGISTRY_IMAGE/webcms-preproduction-dev-drush:$WEBCMS_IMAGE_TAG
- ./twistcli images scan $CI_REGISTRY_IMAGE/webcms-preproduction-dev-drush:$WEBCMS_IMAGE_TAG --address=https://prismacloud.epa.gov --details --token=$PRISMA_CI_TOKEN
after_script:
# Cleanup the above space use on Runner.
Expand All @@ -506,24 +506,24 @@ Database:
variables:
GIT_STRATEGY: none
script:
- 'export PRISMA_CI_TOKEN=$(curl -kH "Content-Type: application/json" -d "{\"username\":\"$PRISMA_CI_USERNAME\", \"password\":\"$PRISMA_CI_PASSWORD\"}" https://prismacloud.epa.gov/api/v22.12/authenticate | jq -r .token)'
- 'export PRISMA_CI_TOKEN=$(curl -kH "Content-Type: application/json" -d "{\"username\":\"$PRISMA_CI_USERNAME\", \"password\":\"$PRISMA_CI_PASSWORD\"}" https://prismacloud.epa.gov/api/v32.01/authenticate | jq -r .token)'
- 'curl --progress-bar -L -k --header "Authorization: Bearer $PRISMA_CI_TOKEN" https://prismacloud.epa.gov/api/v1/util/twistcli > twistcli; chmod a+x twistcli;'
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker pull $CI_REGISTRY_IMAGE/webcms-preproduction-dev-drush:$WEBCMS_IMAGE_TAG
- docker pull $CI_REGISTRY_IMAGE/webcms-preproduction-dev-terraform-database:$WEBCMS_IMAGE_TAG
- ./twistcli images scan $CI_REGISTRY_IMAGE/webcms-preproduction-dev-terraform-database:latest --address=https://prismacloud.epa.gov --details --token=$PRISMA_CI_TOKEN
after_script:
# Cleanup the above space use on Runner.
- rm -rf $CI_PROJECT_DIR
allow_failure: true

Metrics:
.Metrics:
stage: Image Scan
tags:
- twistcli
variables:
GIT_STRATEGY: none
script:
- 'export PRISMA_CI_TOKEN=$(curl -kH "Content-Type: application/json" -d "{\"username\":\"$PRISMA_CI_USERNAME\", \"password\":\"$PRISMA_CI_PASSWORD\"}" https://prismacloud.epa.gov/api/v22.12/authenticate | jq -r .token)'
- 'export PRISMA_CI_TOKEN=$(curl -kH "Content-Type: application/json" -d "{\"username\":\"$PRISMA_CI_USERNAME\", \"password\":\"$PRISMA_CI_PASSWORD\"}" https://prismacloud.epa.gov/api/v32.01/authenticate | jq -r .token)'
- 'curl --progress-bar -L -k --header "Authorization: Bearer $PRISMA_CI_TOKEN" https://prismacloud.epa.gov/api/v1/util/twistcli > twistcli; chmod a+x twistcli;'
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker pull $CI_REGISTRY_IMAGE/webcms-preproduction-dev-fpm-metrics:$WEBCMS_IMAGE_TAG
Expand All @@ -533,14 +533,14 @@ Metrics:
- rm -rf $CI_PROJECT_DIR
allow_failure: true

New Relic:
.New Relic:
stage: Image Scan
tags:
- twistcli
variables:
GIT_STRATEGY: none
script:
- 'export PRISMA_CI_TOKEN=$(curl -kH "Content-Type: application/json" -d "{\"username\":\"$PRISMA_CI_USERNAME\", \"password\":\"$PRISMA_CI_PASSWORD\"}" https://prismacloud.epa.gov/api/v22.12/authenticate | jq -r .token)'
- 'export PRISMA_CI_TOKEN=$(curl -kH "Content-Type: application/json" -d "{\"username\":\"$PRISMA_CI_USERNAME\", \"password\":\"$PRISMA_CI_PASSWORD\"}" https://prismacloud.epa.gov/api/v32.01/authenticate | jq -r .token)'
- 'curl --progress-bar -L -k --header "Authorization: Bearer $PRISMA_CI_TOKEN" https://prismacloud.epa.gov/api/v1/util/twistcli > twistcli; chmod a+x twistcli;'
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker pull $CI_REGISTRY_IMAGE/webcms-preproduction-newrelic-daemon
Expand All @@ -557,7 +557,7 @@ New Relic:
variables:
GIT_STRATEGY: none
script:
- 'export PRISMA_CI_TOKEN=$(curl -kH "Content-Type: application/json" -d "{\"username\":\"$PRISMA_CI_USERNAME\", \"password\":\"$PRISMA_CI_PASSWORD\"}" https://prismacloud.epa.gov/api/v22.12/authenticate | jq -r .token)'
- 'export PRISMA_CI_TOKEN=$(curl -kH "Content-Type: application/json" -d "{\"username\":\"$PRISMA_CI_USERNAME\", \"password\":\"$PRISMA_CI_PASSWORD\"}" https://prismacloud.epa.gov/api/v32.01/authenticate | jq -r .token)'
- 'curl --progress-bar -L -k --header "Authorization: Bearer $PRISMA_CI_TOKEN" https://prismacloud.epa.gov/api/v1/util/twistcli > twistcli; chmod a+x twistcli;'
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker pull $CI_REGISTRY_IMAGE/webcms-preproduction-traefik:latest
Expand All @@ -567,14 +567,14 @@ New Relic:
- rm -rf $CI_PROJECT_DIR
allow_failure: true

CloudWatch:
.CloudWatch:
stage: Image Scan
tags:
- twistcli
variables:
GIT_STRATEGY: none
script:
- 'export PRISMA_CI_TOKEN=$(curl -kH "Content-Type: application/json" -d "{\"username\":\"$PRISMA_CI_USERNAME\", \"password\":\"$PRISMA_CI_PASSWORD\"}" https://prismacloud.epa.gov/api/v22.12/authenticate | jq -r .token)'
- 'export PRISMA_CI_TOKEN=$(curl -kH "Content-Type: application/json" -d "{\"username\":\"$PRISMA_CI_USERNAME\", \"password\":\"$PRISMA_CI_PASSWORD\"}" https://prismacloud.epa.gov/api/v32.01/authenticate | jq -r .token)'
- 'curl --progress-bar -L -k --header "Authorization: Bearer $PRISMA_CI_TOKEN" https://prismacloud.epa.gov/api/v1/util/twistcli > twistcli; chmod a+x twistcli;'
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker pull $CI_REGISTRY_IMAGE/webcms-preproduction-aws-cloudwatch
Expand Down
43 changes: 43 additions & 0 deletions services/drupal/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,49 @@ server {
rewrite ^/(.*)$ /index.php?q=$1;
}

# On any nginx 404, use this internal path
error_page 404 /_404;

# Set up nginx's 404 machinery to return fast-404.html anytime nginx process a 404
location = /_404 {
# Internal means /_404 can't be visited from outside
internal;

# Return the contents of fast-404.html
root /var/www/html/web/themes/epa_theme/source;
try_files /fast-404.html =404;
}

# For each listed path, return HTTP 410 Gone, using our 404 template instead:
# users will see a "page not found" page, but code will see a "this page will
# never return" status code. Hopefully this will defray some of the ongoing
# load.
location ^~ /newsreleases/search/ {
error_page 410 /_404;
return 410;
}

location ^~ /faqs/search/ {
error_page 410 /_404;
return 410;
}

location ^~ /publicnotices/notices-search/ {
error_page 410 /_404;
return 410;
}

location ^~ /perspectives/search/ {
error_page 410 /_404;
return 410;
}

location ^~ /speeches/search/ {
error_page 410 /_404;
return 410;
}


# This prevents nginx's view of the filesystem from conflicting with the Drupal node of
# the same name.
location = /libraries {
Expand Down

0 comments on commit 6e29d91

Please sign in to comment.