Skip to content

fix(nginx): redirect to https, so none drops to http - #1146

Merged
cjorge-thegraph merged 1 commit into
mainfrom
fix/nginx-https-redirects
Dec 3, 2026
Merged

cjorge-thegraph merged 1 commit into
mainfrom
fix/nginx-https-redirects

Conversation

@cjorge-thegraph

Copy link
Copy Markdown
Contributor

Problem

TLS ends before nginx (Cloudflare → Envoy Gateway → plain http on :80), so $scheme is always http. Every redirect to this site was built as $scheme://$http_host/.... As a result, https://thegraph.com/docs/ → 301 http://thegraph.com/docs/en/ → (Cloudflare "Always Use HTTPS") → https://thegraph.com/docs/en/. That is an extra hop and a downgrade to http.

Change

All 194 $scheme://$http_host/... targets in nginx.conf become https://$host/...: the normalisation rules, the locale rules, every permanent (301) redirect and the two temporary (302) ones. Paths, query-string handling (rewrite still appends args exactly as before) and statuses are unchanged. No other file changes.

Why absolute, not relative: we tried relative redirects (absolute_redirect off). They turn /\evil into Location: /\evil/, and browsers read /\ as //, which makes it an open redirect to another site. An absolute https://<host>/ target pins the host.

Why $host and not $http_host: $host is the name nginx matched for the request (lowercased, port stripped), not the raw header. Behind Cloudflare it is always thegraph.com or the staging host. thegraph.com:8443 now gives https://thegraph.com/..., not a port on https. The server block has no server_name, so it is the catch-all: a direct request with a foreign Host (evil.example) still gets https://evil.example/..., as it got http://evil.example/... before. Only the client that sends that header sees it, so it cannot redirect someone else's browser. The existing X-Forwarded-Proto → https rule is kept as is.

Tested (nginx:1.16.0-alpine, this conf, minimal static tree, Host: thegraph.com)

Request Before (main) After
/docs/ 301 http://thegraph.com/docs/en/ 301 https://thegraph.com/docs/en/
/docs 301 http://…/docs/ 301 https://…/docs/
/docs/en 301 http://…/docs/en/ 301 https://…/docs/en/
/docs/es 301 http://…/docs/es/ 301 https://…/docs/es/
/docs/en/ 200 200
/docs/en/subgraphs/ 301 http://…/docs/en/subgraphs/overview/ 301 https://…/docs/en/subgraphs/overview/
/docs/en/subgraphs/?a=1 301 http://…/subgraphs/overview/?a=1 301 https://…/subgraphs/overview/?a=1
/docs/es/subgraphs/?a=1 301 http://…/docs/en/subgraphs/?a=1 301 https://…/docs/en/subgraphs/?a=1
/docs/en/billing/ 301 http://…/subgraphs/providers/graph-foundation/overview/ 301 https://…/subgraphs/providers/graph-foundation/overview/
/docs/en/cookbook/grafting/?x=y 301 http://…/best-practices/grafting/?x=y 301 https://…/best-practices/grafting/?x=y
/docs/en/resources/delegating/undelegating/ 301 http://…/resources/delegating/#how-to-undelegate-on-the-graph 301 https://… (same path)
/docs/en/supported-networks/btc/ 301 http://…/supported-networks/bitcoin/ 301 https://…/supported-networks/bitcoin/
/docs/en/querying/graph-client/ 302 http://…/graph-client/README/ 302 https://…/graph-client/README/
/docs/en/hypergraph/ (external) 301 https://github.com/graphprotocol/hypergraph unchanged
/docs/_next/a.js 200 200
/docs/en/no-such-page/ 200 (localized 404 page) 200 (unchanged)
/nope.txt 404 404
/\evil, /%5Cevil 301 http://thegraph.com/\evil/ 301 https://thegraph.com/\evil/
//evil, /%2F%2Fevil 301 http://thegraph.com/evil 301 https://thegraph.com/evil
/docs//evil 301 http://thegraph.com/docs/evil 301 https://thegraph.com/docs/evil
Host: thegraph.com:8443 /docs/ 301 http://thegraph.com:8443/docs/en/ 301 https://thegraph.com/docs/en/
Host: evil.example /docs/ 301 http://evil.example/docs/en/ 301 https://evil.example/docs/en/

The full 28-path matrix (plus slash-normalisation cases) matches line for line: the same status and the same path and query on every row. The only differences are http → https and the $host normalisation. No Location is protocol-relative.

Expected live result: https://thegraph.com/docs/ → 301 https://thegraph.com/docs/en/ → 200. One hop, never http.

Release safety

When this PR was opened, main was identical to v2.1.16 (compare/v2.1.16...main: ahead_by 0). Tag the release at this PR's merge commit. Staging follows latest (built from main by image.yml). Production only moves on a vX.Y.Z GitHub release, whose tag release.yml copies from the main build's image.

🤖 Generated with Claude Code

TLS ends before nginx, so $scheme is always http and every redirect to
this site sent browsers to http first. Redirect to https://$host/...
instead: one hop, never http. Paths, query handling and statuses are
unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cjorge-thegraph
cjorge-thegraph merged commit 36e2a93 into main Dec 3, 2026
4 checks passed
@cjorge-thegraph
cjorge-thegraph deleted the fix/nginx-https-redirects branch December 3, 2026 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants