如何停止 Fastly HTTPS 308 永久重定向?
How to stop Fastly HTTPS 308 Permanent Redirect?
我有一个 Fastly Compute@Edge 服务,该服务配置为对前端域和后端主机使用 HTTP,但是当我连接时,我得到一个 308 https 重定向,我想停止它。我希望它只是 运行 和 return 似乎没有执行的 Edge 函数代码。
我的域是 www.goodapis.com
,CNAME 配置为指向 nonssl.global.fastly.net.
,如下所示:
% dig www.goodapis.com +short
nonssl.global.fastly.net.
151.101.188.204
我的后端主机指向 example.com:80
(也没有 TLS),不过现在这应该无关紧要,因为加载的边缘代码不会调用后端主机。
我的 Edge 代码包是来自以下 repo 的演示代码:
https://github.com/fastly/compute-starter-kit-javascript-default
使用以下代码(此处删除了一些注释):
https://github.com/fastly/compute-starter-kit-javascript-default/blob/main/src/index.js
//! Default Compute@Edge template program.
/// <reference types="@fastly/js-compute" />
import welcomePage from "./welcome-to-compute@edge.html";
// The entry point for your application.
//
// Use this fetch event listener to define your main request handling logic. It could be
// used to route based on the request properties (such as method or path), send
// the request to a backend, make completely new requests, and/or generate
// synthetic responses.
addEventListener("fetch", (event) => event.respondWith(handleRequest(event)));
async function handleRequest(event) {
// Get the client request.
let req = event.request;
// Filter requests that have unexpected methods.
if (!["HEAD", "GET"].includes(req.method)) {
return new Response("This method is not allowed", {
status: 405,
});
}
let url = new URL(req.url);
// If request is to the `/` path...
if (url.pathname == "/") {
// <cut comments>
// Send a default synthetic response.
return new Response(welcomePage, {
status: 200,
headers: new Headers({ "Content-Type": "text/html; charset=utf-8" }),
});
}
// Catch all other requests and return a 404.
return new Response("The page you requested could not be found", {
status: 404,
});
}
然而,当我调用http://www.goodapis.com, I get a 308 Permanent Redirect to https://www.goodapis.com。当我发送 POST
以及清除整个缓存后,就会发生这种情况。
% curl http://www.goodapis.com --verbose
* Trying 151.101.40.204:80...
* Connected to www.goodapis.com (151.101.40.204) port 80 (#0)
> GET / HTTP/1.1
> Host: www.goodapis.com
> User-Agent: curl/7.77.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 308 Permanent Redirect
< Server: Varnish
< Retry-After: 0
< Content-Length: 0
< Location: https://www.goodapis.com/
< Accept-Ranges: bytes
< Date: Mon, 23 May 2022 21:08:25 GMT
< Via: 1.1 varnish
< Connection: close
< X-Served-By: cache-sjc10043-SJC
< X-Cache: HIT
< X-Cache-Hits: 0
<
* Closing connection 0
任何人都知道为什么会发生此 308 重定向以及如何停止它?
Fastly 的 Compute@Edge 平台不支持 HTTP 连接。所以这些请求会被自动重定向。
此处的 Fastly 文档对此进行了描述:
https://developer.fastly.com/learning/compute/#limitations-and-constraints
Compute@Edge services allow connections to backends on ports 80 and 443, and accept client connections on port 443 only.
如果您还有任何问题,请随时联系支持@fastly.com
谢谢。
我有一个 Fastly Compute@Edge 服务,该服务配置为对前端域和后端主机使用 HTTP,但是当我连接时,我得到一个 308 https 重定向,我想停止它。我希望它只是 运行 和 return 似乎没有执行的 Edge 函数代码。
我的域是 www.goodapis.com
,CNAME 配置为指向 nonssl.global.fastly.net.
,如下所示:
% dig www.goodapis.com +short
nonssl.global.fastly.net.
151.101.188.204
我的后端主机指向 example.com:80
(也没有 TLS),不过现在这应该无关紧要,因为加载的边缘代码不会调用后端主机。
我的 Edge 代码包是来自以下 repo 的演示代码:
https://github.com/fastly/compute-starter-kit-javascript-default
使用以下代码(此处删除了一些注释):
https://github.com/fastly/compute-starter-kit-javascript-default/blob/main/src/index.js
//! Default Compute@Edge template program.
/// <reference types="@fastly/js-compute" />
import welcomePage from "./welcome-to-compute@edge.html";
// The entry point for your application.
//
// Use this fetch event listener to define your main request handling logic. It could be
// used to route based on the request properties (such as method or path), send
// the request to a backend, make completely new requests, and/or generate
// synthetic responses.
addEventListener("fetch", (event) => event.respondWith(handleRequest(event)));
async function handleRequest(event) {
// Get the client request.
let req = event.request;
// Filter requests that have unexpected methods.
if (!["HEAD", "GET"].includes(req.method)) {
return new Response("This method is not allowed", {
status: 405,
});
}
let url = new URL(req.url);
// If request is to the `/` path...
if (url.pathname == "/") {
// <cut comments>
// Send a default synthetic response.
return new Response(welcomePage, {
status: 200,
headers: new Headers({ "Content-Type": "text/html; charset=utf-8" }),
});
}
// Catch all other requests and return a 404.
return new Response("The page you requested could not be found", {
status: 404,
});
}
然而,当我调用http://www.goodapis.com, I get a 308 Permanent Redirect to https://www.goodapis.com。当我发送 POST
以及清除整个缓存后,就会发生这种情况。
% curl http://www.goodapis.com --verbose
* Trying 151.101.40.204:80...
* Connected to www.goodapis.com (151.101.40.204) port 80 (#0)
> GET / HTTP/1.1
> Host: www.goodapis.com
> User-Agent: curl/7.77.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 308 Permanent Redirect
< Server: Varnish
< Retry-After: 0
< Content-Length: 0
< Location: https://www.goodapis.com/
< Accept-Ranges: bytes
< Date: Mon, 23 May 2022 21:08:25 GMT
< Via: 1.1 varnish
< Connection: close
< X-Served-By: cache-sjc10043-SJC
< X-Cache: HIT
< X-Cache-Hits: 0
<
* Closing connection 0
任何人都知道为什么会发生此 308 重定向以及如何停止它?
Fastly 的 Compute@Edge 平台不支持 HTTP 连接。所以这些请求会被自动重定向。
此处的 Fastly 文档对此进行了描述: https://developer.fastly.com/learning/compute/#limitations-and-constraints
Compute@Edge services allow connections to backends on ports 80 and 443, and accept client connections on port 443 only.
如果您还有任何问题,请随时联系支持@fastly.com
谢谢。