<!-- Generated from ja/llms-txt-cloudflare/index.html. The canonical document is the HTML page. -->

- [ ホーム ](/ja/) 
/
- [ 作成方法 ](/ja/how-to-create/) 
/
- Cloudflare Pages ガイド            
# Cloudflare Pages での `llms.txt`

2つの方法があります。ビルド出力ディレクトリに静的ファイルを置いて設定なしですぐデプロイするか、動的コンテンツ用のCloudflare Pages Functionを使用します。

最終更新: 2026年4月22日

このページの内容

- [ アプローチ1：ビルド出力内の静的ファイル ](#approach-1)
- [ アプローチ 2、Cloudflare Pages 機能 ](#approach-2)
- [ 代替案：Cloudflare Worker ](#workers)
- [ キャッシュヘッダーと CDN の動作 ](#cache)
- [ デプロイ後に検証すること ](#verify)              
例

このサイトは Cloudflare Pages で稼働しています

llmtxt.infoはGitHub経由でCloudflare Pagesにデプロイされている。独自の  /llms.txt 
は静的ファイル方式（以下の方式1）で配信されています。実際のヘッダーは
curl -I https://llmtxt.info/llms.txt .

## アプローチ1：ビルド出力内の静的ファイル

最も簡単な選択肢です。Cloudflare Pages
は、ビルド出力ディレクトリ内のすべてのファイルをグローバル CDN
から直接配信します。Workers、Functions、設定変更は不要です。
static file, framework directory map    コピー     

```
# For any framework deployed on Cloudflare Pages,
# place llms.txt in the directory that gets published.
#
# Framework       → file location
# Astro           → public/llms.txt
# Next.js         → public/llms.txt
# SvelteKit       → static/llms.txt
# Hugo            → static/llms.txt
# Eleventy        → _site root (copy via passthrough)
# Plain HTML      → project root or output folder

# After deploy, Cloudflare serves it at /llms.txt from their global CDN.
# Verify:
curl -I https://your-domain.com/llms.txt
# Expected: HTTP/2 200 | Content-Type: text/plain | CF-Cache-Status: HIT
```

正しい配置場所はフレームワークによって異なります：

- **Astro** → `public/llms.txt` （ `dist/` （自動的にコピー） 
- **Next.js** → `public/llms.txt` （Cloudflare PagesのNext.jsアダプターが
対応） 
- **SvelteKit** → `static/llms.txt` 
- **Hugo** → `static/llms.txt` 
- **Eleventy** → パススルーコピーを追加します： `eleventyConfig.addPassthroughCopy("llms.txt")` 
- **プレーンHTML** → ビルド出力ディレクトリに指定したフォルダーに置きます   
一度デプロイされると、Cloudflare はそのファイルを世界中のエッジネットワークから配信します。
`Content-Type: text/plain` ヘッダーは、次に基づいて自動的に設定されます:
`.txt` 拡張子です。

例

GitHub 連携

Cloudflare Pagesは、GitHub（またはGitLab）リポジトリに直接接続します。
本番ブランチへのプッシュごとに、新しいビルドとデプロイがトリガーされます。コミットすると  public/llms.txt 
だけで完了し、手動アップロードは不要です。

## アプローチ 2、Cloudflare Pages 機能

Cloudflare Pages Functionsでは、Cloudflare
Workersランタイム上で動作するTypeScriptコードを使い、特定のルートを処理できます。次の場所にファイルを作成します:
`functions/llms.txt.ts` そして自動的に `/llms.txt`.
functions/llms.txt.ts, hardcoded content    コピー     

```
// functions/llms.txt.ts
// Cloudflare Pages Functions use the file path as the route.
// This file handles GET requests to /llms.txt

interface Env {
// Add KV namespace or D1 bindings here if needed
}

export const onRequestGet: PagesFunction  = async (context) => {
// Build content, hardcode here or pull from KV / D1 / API
const content = [
'# My Site',
'',
'> One-sentence description of what this site is about.',
'',
'## Documentation',
'',
'- [Getting started](https://yoursite.com/docs/getting-started/): first steps.',
'- [API reference](https://yoursite.com/docs/api/): full endpoint catalog.',
'',
'## Optional',
'',
'- [Changelog](https://yoursite.com/changelog/): version history.',
].join('\n');

return new Response(content, {
headers: {
'Content-Type': 'text/plain; charset=utf-8',
// Cache at the edge for 1 hour, allow stale for 24h
'Cache-Control': 'public, max-age=3600, stale-while-revalidate=86400',
},
});
};

```

**使用すべき場面：** データソース（データベース、 CMS API、KVストア）からファイルを生成したい場合、サイト全体を再構築せずに済みます。例：
[KV Namespace](https://developers.cloudflare.com/kv/):
functions/llms.txt.ts, KV-backed content    コピー     

```
// functions/llms.txt.ts, pulling content from KV
// Useful if you update the file from a CMS webhook without redeploying.

interface Env {
LLMS_TXT: KVNamespace;
}

export const onRequestGet: PagesFunction  = async ({ env }) => {
const content = await env.LLMS_TXT.get('content');

if (!content) {
return new Response('# My Site\n\n> Content not configured yet.', {
status: 200,
headers: { 'Content-Type': 'text/plain; charset=utf-8' },
});
}

return new Response(content, {
headers: {
'Content-Type': 'text/plain; charset=utf-8',
'Cache-Control': 'public, max-age=300, stale-while-revalidate=3600',
},
});
};

```

KVアプローチを使用すると、コンテンツを更新することができます。 `/llms.txt` KV 名前空間へ書き込むことで（API、ダッシュボード、CMS
からの Webhook 経由）、Pages 全体をデプロイせずに更新できます。

警告

Pages Functionと静的ファイルの比較

両方の  functions/llms.txt.ts  および静的な  llms.txt  がビルド出力に存在する場合、Pages
Function が優先されます。両方ではなく、どちらか一方の方式を使用してください。

## Cloudflare Worker の代替案

サイトが Cloudflare Pages 上になくても、Cloudflare を CDN/DNS
プロキシとして使用している場合は、次をインターセプトできます： `/llms.txt` パスを、スタンドアロンのCloudflare
Workerと
[ルートパターン](https://developers.cloudflare.com/workers/configuration/routing/routes/):
Cloudflare Worker, standalone    コピー     

```
// Cloudflare Worker, wrangler.toml config
// Use this if you want a standalone Worker (not tied to Pages).

// wrangler.toml
// name = "llms-txt-worker"
// main = "src/index.ts"
// compatibility_date = "2024-09-01"
//
// [[routes]]
// pattern = "yoursite.com/llms.txt"
// zone_name = "yoursite.com"

// src/index.ts
export default {
async fetch(request: Request): Promise  {
const content = `# My Site

> One-sentence description.

## Core pages

- [Getting started](https://yoursite.com/docs/getting-started/): first steps.
- [API reference](https://yoursite.com/docs/api/): full endpoint catalog.
`;

return new Response(content, {
headers: {
'Content-Type': 'text/plain; charset=utf-8',
'Cache-Control': 'public, max-age=3600',
},
});
},
} satisfies ExportedHandler;

```

## CacheヘッダーとCDNの動作

Cloudflareはビルド出力内の静的ファイルを自動的にキャッシュします。静的ファイルではキャッシュヘッダーを設定する必要はなく、CloudflareはPagesプロジェクト設定の既定TTLに従います。

Pages Functions では、 `Cache-Control` レスポンス内で明示的に設定します。推奨:

- `public, max-age=3600`、エッジで1時間キャッシュする（手動管理ファイルに適している）。 
- `public, max-age=3600, stale-while-revalidate=86400`、バックグラウンドで再検証しながら最大 24 時間は古い内容を配信します。 
- `public, max-age=300`, 頻繁に更新されるKVベースのコンテンツ向けの5分間キャッシュ。   
新しいバージョンをデプロイすると、Cloudflare は変更された静的
ファイルのキャッシュを自動的に無効化します。Pages Functions
については、直ちに無効化が必要な場合は、 Cloudflare ダッシュボードまたは API を使用して、特定の
URL のキャッシュをパージしてください。

## デプロイ後に検証すること
verify    コピー     

```
# Check headers, look for Content-Type and CF-Cache-Status
curl -I https://yoursite.com/llms.txt

# Check content
curl https://yoursite.com/llms.txt

# Purge Cloudflare cache if you deployed a new version:
# Dashboard → Caching → Configuration → Purge Everything
# or via API:
curl -X POST "https://api.cloudflare.com/client/v4/zones/{ZONE_ID}/purge_cache" \
-H "Authorization: Bearer {CF_API_TOKEN}" \
-H "Content-Type: application/json" \
--data '{"files":["https://yoursite.com/llms.txt"]}'
```

ヘッダーを確認したら、公開URLを [バリデーター](/ja/validator/)
で仕様への準拠を確認します。H1が正確に1つあること、リンク構文が有効であること、すべてのURLが絶対URLであること、空のセクションがないことを確認してください。

→ [完全な作成ガイド](/ja/how-to-create/) &middot;
[Astroガイド](/ja/llms-txt-astro/) &middot;
[Next.js ガイド](/ja/llms-txt-nextjs/)

## ソース

- [ llmstxt.org、コミュニティによる提案 ](https://llmstxt.org/)
- [ Cloudflare Pages、Functions ](https://developers.cloudflare.com/pages/functions/)
- [ Cloudflare、稼働中のllms.txtの例 ](https://www.cloudflare.com/llms.txt)
