我只是有一个问题,我想获取访问者的 IP 地址。一切都很好,但一位用户只给了我 IPv6。这是我可以给你的代码,而且我刚刚安装了cloudflare apache2 Mod。
$_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"] ? $_SERVER["HTTP_CF_CONNECTING_IP"] : $_SERVER["REMOTE_ADDR"];
$ip = $_SERVER['REMOTE_ADDR'];
if(isset($_SERVER['HTTP_CF_CONNECTING_IP'])){
$ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
}
Run Code Online (Sandbox Code Playgroud) 在将请求发送到 node.js api 后,我尝试以编程方式清除单个 url 的 cloudflare 缓存。我正在使用https://github.com/cloudflare/node-cloudflare库,但是我不知道如何记录来自 cloudflare 的回调。根据同一存储库中的测试文件,语法应该是这样的:
//client declaration:
t.context.cf = new CF({
key: 'deadbeef',
email: 'cloudflare@example.com',
h2: false
});
//invoke clearCache:
t.context.cf.deleteCache('1', {
files: [
'https://example.com/purge_url'
]
})
Run Code Online (Sandbox Code Playgroud)
我如何从这个请求中读出回调?我在自己的代码中尝试了以下操作:
client.deleteCache(process.env.CLOUDFLARE_ZONE, { "files": [url] }, function (data) {
console.log(`Cloudflare cache purged for: ${url}`);
console.log(`Callback:${data}`);
})
Run Code Online (Sandbox Code Playgroud)
和:
client.deleteCache('1', {
files: [
'https://example.com/purge_url'
]
}).then(function(a,b){
console.log('helllllllooooooooo');
})
Run Code Online (Sandbox Code Playgroud)
无济于事。:(
我正在使用名为 images.example.com 的 Amazon S3 存储桶,该存储桶使用如下 URL 成功通过 Cloudflare CDN 提供内容:
https://images.example.com/myfile.jpg
Run Code Online (Sandbox Code Playgroud)
我想防止热链接到图像和其他内容,购买限制仅访问引用域:example.com 以及可能用作开发服务器的另一个域。
我尝试过一种存储桶策略,它既允许来自特定域,又拒绝来自任何非特定域的域:
{
"Version": "2012-10-17",
"Id": "http referer policy example",
"Statement": [
{
"Sid": "Allow get requests referred by www.example.com",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::images.example.com/*",
"Condition": {
"StringLike": {
"aws:Referer": [
"http://www.example.com/*",
"http://example.com/*"
]
}
}
},
{
"Sid": "Explicit deny to ensure requests are allowed only from specific referer.",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": "arn:aws:s3:::images.example.com/*",
"Condition": {
"StringNotLike": {
"aws:Referer": [ …Run Code Online (Sandbox Code Playgroud) 我目前有两个在 cloudflare 中使用以下 CNAME 设置的 Web 应用程序。两者都是 keystonejs 应用程序。
app1.example.com ===pointing to ===> AWS ALB 1
app2.example.com ===pointing to ===> AWS ALB 2
Run Code Online (Sandbox Code Playgroud)
我已设置 Cloudflare Enterprise,因此我可以在页面规则中使用“渲染覆盖”功能。我使用以下内容设置了 2 个页面规则:
www.example.com ===render override ===> app1.example.com
www.example.com/app2/* ===render override ===> app2.example.com
Run Code Online (Sandbox Code Playgroud)
现在为了访问 app2.example.com 上的 keystonejs 应用程序。使用 app2.example.com/pa 调用该应用程序
我面临的问题是渲染覆盖不允许我使用子路径,并且我不想使用转发规则。我是否需要通过根 URL(即 app2.example.com/ )访问我的 keystone 应用程序?或者还有其他方法可以做到这一点吗?否则,我需要使用反向代理吗?比如nginx?谢谢
cloudflare keystonejs cloudflare-workers terraform-provider-cloudflare
我的 DNS 使用 Cloudflare 并且 SSL 已满。我正在尝试设置一个子域;https://humlor.myrenas.se并将其指向 AWS S3-bucket。我已经使用默认的 CloudFront 证书 (*.cloudfront.net) 设置了 Cloudfront,该站点可在https://d2ufhnw2kk1vh9.cloudfront.net/ 上找到(没有设置 CSS 的一些绝对路径的样式)
然后我在 Cloudflare 中创建了一个 CNAME 记录:CNAME humlor is an alias of d2ufhnw2kk1vh9.cloudfront.net
但是https://humlor.myrenas.se/给出:403 ERROR 无法满足请求。错误的请求。
我需要在 Cloudfront 中使用另一个证书吗?或者缺少什么?
我正在使用 CloudFlare 来管理我的网站 DNS。我想使用页面规则为多个 URL 设置重定向以转到另一个网站 URL。
目前我的托管帐户,我已将它们全部设置为插件域,然后在 CPanel 中设置重定向。
我正在将我的站点移动到我自己的云服务器,而无需 CPanel - 我正在使用 VestaCP。我不想通过添加我想要重定向到主机的每个网站(有十几个)来弄乱网站记录 - 我希望 Cloudflare 来管理这一切。
是否有可能做到这一点?喜欢使用 Cloudflare 页面规则并删除指向主机服务器 IP 的 A 记录吗?
我使用 .htaccess 文件将目录访问权限限制为某些 IP 地址,如下所示:
AuthType Basic
AuthName "Protected"
<RequireAny>
Require ip 1.2.3.4
</RequireAny>
Run Code Online (Sandbox Code Playgroud)
这在正常的服务器设置中工作正常,但是当使用 Cloudflare 作为 WAF 代理时,它停止工作,因为服务器接收通过 Cloudflare 的 IP 代理的所有请求。
作为一种解决方法,可以使用“X-Forwarded-For”标头来识别客户端的“真实”IP 地址,因为 Cloudflare 将其与其所有请求一起传递:
AuthType Basic
AuthName "Protected"
SetEnvIf X-Forwarded-For 1.2.3.4$ allowed
<RequireAny>
Require env allowed
</RequireAny>
Run Code Online (Sandbox Code Playgroud)
这是一种安全的方法,还是在使用 Cloudflare 时有更好/更安全的方法来限制 Apache 中客户端 IP 的访问?
当我部署到生产环境时,我尝试curl向 bitbucket 上的 CI/CD YAML 添加命令。该curl命令向 CloudFlare API 发送 POST 请求以清除缓存。该命令包含-H变量作为必要的 HTTP 标头。这导致 bitbucket 上出现缩进错误,因此我无法提交更改,而且我不确定原因。我不熟悉 YAML 语法以及如何解决此问题。
bitbucket-pipelines.YAML
image: python:3.7.4
clone:
depth: full
pipelines:
default:
- step:
caches:
- pip
script:
- echo "nothing"
branches:
prod:
- step:
name: Deploy to Staging
deployment: staging
script: #staging script
- git push https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_STAGING_APP_NAME.git HEAD:master --force
- step:
name: Deploy to Production
deployment: production
trigger: manual
script: #production script
- git push https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_APP_NAME.git HEAD:master --force
- "curl …Run Code Online (Sandbox Code Playgroud) Cloudflare 自己的全球分布式数据存储 \xe2\x80\x93 Workers KV \xe2\x80\x93可以接受三种“类型”的数据:string、ArrayBuffer和ReadableStream。
虽然前两者的用例足够清楚,但我正在努力弄清楚存储如何ReadableStream有用。我熟悉这个概念:使用它,您可以随着时间的推移“流式传输”不同的值,但是将其放入数据存储中有何意义?典型场景有哪些?
distributed-computing cloudflare serverless cloudflare-workers
我使用 CF Workers 创建了一个 SendGrid 表单并设置(用于测试)Access-Control-Allow-Origin", '*' 但它在前端被忽略:
Access to XMLHttpRequest at 'https://<domain>.workers.dev/' from origin 'https://<frontend-domain>.dev' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Run Code Online (Sandbox Code Playgroud)
我是否还需要将其添加到 AXIOSPOST请求中?
这是我的工人文件中的代码:
const myHeaders = new Headers();
myHeaders.set("Access-Control-Allow-Origin", '*');
myHeaders.set("Access-Control-Allow-Methods", "GET,HEAD,POST,OPTIONS");
myHeaders.set("Access-Control-Max-Age", "86400",);
return new Response((emailResponse.ok), {status: 200, headers: myHeaders})
Run Code Online (Sandbox Code Playgroud)
这是 AXIOS 请求:
this.$axios.$post(
"https://<domain>.workers.dev/",
{
name: this.mailData.name,
eMail: this.mailData.eMail,
phone: this.mailData.phone,
message: this.mailData.message,
},
{
headers: …Run Code Online (Sandbox Code Playgroud) cloudflare ×10
amazon-s3 ×2
ajax ×1
apache ×1
api ×1
axios ×1
bitbucket ×1
callback ×1
dns ×1
hotlinking ×1
ipv4 ×1
javascript ×1
keystonejs ×1
linux ×1
node.js ×1
purge ×1
redirect ×1
serverless ×1
syntax-error ×1
terraform-provider-cloudflare ×1
yaml ×1