如何快速停止 HTTPS 308 永久重定向?
发布时间:2022-05-27 03:57:52 333
相关标签: # javascript# 前端# html# edge# git
我有一个快速Compute@Edge配置为对前端域和后端主机使用HTTP的服务,但当我连接时,会收到308 https重定向,我想停止该重定向。我希望它只运行并返回似乎没有执行的边缘函数代码。
我的域名是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)。
我的边缘代码包来自以下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.
///
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 == "/") {
//
// 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,我得到一个308永久重定向到https://www.goodapis.com.在清除整个缓存后也会发生这种情况。
% 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重定向为什么会发生,以及如何停止吗?
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报