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

- [ 首页 ](/zh/) 
/
- [ 如何创建 ](/zh/how-to-create/) 
/
- Nuxt.js 指南            
# Nuxt.js 的 `llms.txt`

Nuxt.js 的三种做法：在 public/ 中放静态文件（零配置），用 Nitro 服务器路由动态生成，或从 Nuxt Content 文档自动生成。

最近更新: 2026年4月22日

本页内容

- [ public/ 中的选项 1：静态文件 ](#static)
- [ 选项 2：服务器 API 路由 ](#server-route)
- [ 选项 3：Nuxt Content 自动生成 ](#nuxt-content)
- [ Nitro 和部署目标 ](#nitro)
- [ 验证 ](#verify)              
备注

应使用哪种方案？

使用  静态文件  ，如果您的  llms.txt  很少变化。使用  服务器路由  如果你希望在请求时或构建时从内容生成它。使用  Nuxt Content 集成  ，适合使用 Markdown
文件管理文档的情况。

## public/ 中的选项 1：静态文件

Nuxt 会将 `public/` 目录中的内容直接复制到构建输出中，并通过 网站根路径提供。请将文件放在 `public/llms.txt` ，并可通过以下位置访问： `/llms.txt` 在每个部署目标上。
public/llms.txt, directory structure    复制     

```
# Nuxt static file approach
#
# Place your file at: public/llms.txt
# Nuxt copies everything in public/ directly to the build output.
#
# Project structure:
# your-nuxt-app/
# ├── public/
# │   └── llms.txt   ← add this
# ├── pages/
# └── nuxt.config.ts
#
# No configuration needed. Works with all deployment presets.

```

此方案无需配置，并且在所有 Nitro 预设中都以相同方式运行： **node-server**, **cloudflare-pages**, **vercel**, **netlify**，以及 **静态**.

## 选项 2：服务端 API 路由

在 `server/routes/llms.txt.ts`。Nuxt 的 Nitro 引擎会将以下目录中的文件映射到 URL
路径： `server/routes/` 直接映射到网址路径，因此此文件准确地通过 `/llms.txt` ，无需额外的 路由配置。
server/routes/llms.txt.ts    复制     

```
// server/routes/llms.txt.ts
// Nuxt server route, served at /llms.txt
export default defineEventHandler(() => {
const content = `# Your Site

> One-sentence description of what your site or product does.

## Documentation

- [Getting Started](https://yoursite.com/docs/start): Install and configure in minutes.
- [API Reference](https://yoursite.com/docs/api): Full endpoint catalog with examples.

## Product

- [Overview](https://yoursite.com/product): Core features and capabilities.
- [Pricing](https://yoursite.com/pricing): Plans and billing details.

## Optional

- [Changelog](https://yoursite.com/changelog): Release history.
- [GitHub](https://github.com/your-org/your-repo): Source code.
`;

setResponseHeader(event, 'Content-Type', 'text/plain; charset=utf-8');
setResponseHeader(event, 'Cache-Control', 'public, max-age=3600, stale-while-revalidate=86400');
return content;
});

```

使用 `setResponseHeader` 从 `h3` 库（随 Nuxt 捆绑）来设置正确的 `Content-Type`。添加一个 `Cache-Control` 通过 header 让 CDN 边缘缓存响应并降低源站负载。

## 选项 3：Nuxt Content 自动生成

如果你使用 [Nuxt Content](https://content.nuxt.com/) 管理文档，则可以查询内容集合并自动构建链接列表。这样可以确保
`llms.txt` 无需手动更新即可与文档保持同步。
server/routes/llms.txt.ts, Nuxt Content    复制     

```
// server/routes/llms.txt.ts
// Auto-generate llms.txt from Nuxt Content documents
import { serverQueryContent } from '#content/server';

export default defineEventHandler(async (event) => {
// Query all docs; adjust collection name as needed
const docs = await serverQueryContent(event, '/docs')
.only(['title', 'description', '_path'])
.find();

const links = docs
.map((doc) => `- [${doc.title}](https://yoursite.com${doc._path}/): ${doc.description ?? ''}`)
.join('\n');

const body = [
'# Your Site',
'',
'> One-sentence description of your project.',
'',
'## Documentation',
'',
links,
].join('\n');

setResponseHeader(event, 'Content-Type', 'text/plain; charset=utf-8');
return body;
});

```

调整查询路径（`/docs`）和字段名称以匹配你的内容结构。运行 [验证器](/zh/validator/) ，以发现任何格式回归。

## Nitro 和部署目标

- **node-server**，服务器路由以 Node.js HTTP
处理程序的形式运行。为其添加反向代理（nginx/Caddy）缓存规则： `/llms.txt` 以避免每次请求都命中
Node。 
- **cloudflare-pages**，位于 `public/` 通过 Cloudflare 的全球 CDN 提供。服务器路由会成为
Pages Functions。请参阅 [Cloudflare 指南](/zh/llms-txt-cloudflare/) 的缓存标头。 
- **vercel**，静态文件会自动在边缘缓存。根据配置，服务器路由会成为 Vercel
Serverless Function 或 Edge Function。 
- **静态** （完全预渲染），请使用 `public/` 
静态文件方案；纯静态输出不支持服务器路由。   
## 验证

部署后，确认文件已正确提供：
Verification    复制     

```
curl -I https://yoursite.com/llms.txt
# Expected:
# HTTP/2 200
# content-type: text/plain; charset=utf-8

curl https://yoursite.com/llms.txt | head -5
# Should print the first lines of your file
```

## 相关指南

- [如何创建 llms.txt](/zh/how-to-create/)、模板和检查清单。 
- [llms.txt 格式参考](/zh/llms-txt-format/)，规范细节。 
- [Vercel 指南](/zh/llms-txt-vercel/)，部署和缓存头。 
- [Cloudflare Pages 指南](/zh/llms-txt-cloudflare/)，CDN 配置。 
- [验证器](/zh/validator/) · [生成器](/zh/generator/).        
## 来源

- [ llmstxt.org，社区提案 ](https://llmstxt.org/)
- [ Nuxt 文档，服务器路由 ](https://nuxt.com/docs/guide/directory-structure/server)
- [ Nuxt Content 文档 ](https://content.nuxt.com/)
