在反向代理后运行
终止 TLS,并将 HTTP 路由到您的服务器。
在反向代理后运行 是 CoddyKit 上的免费 MCP Academy 课时。 这是第 2 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 MCP Academy 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 MCP Academy 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
What a Reverse Proxy Is
A reverse proxy sits in front of your server, taking requests from the internet and quietly forwarding them to your MCP process. 🔀
Why Put One in Front
Your MCP server should focus on logic, not the messy public edge. A proxy handles TLS, routing, and shielding so your code stays simple.
Terminate TLS at the Edge
The proxy decrypts incoming HTTPS and speaks plain HTTP to your server inside. This TLS termination keeps certificates in one place.
Nginx Is a Common Choice
Nginx is a popular, battle-tested reverse proxy. A small config block is enough to route public traffic to your MCP container.
Forward to Your Server
The key directive is proxy_pass, which points the proxy at your server's internal address and port.
location /mcp {
proxy_pass http://127.0.0.1:8000;
}Pass Through the Right Headers
Forward headers like Host and the client's real IP so your server sees accurate request info, not just the proxy itself.
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;Keep Streaming Alive
MCP can stream replies, so disable response buffering for the endpoint. Otherwise the proxy holds events back until the call ends.
proxy_buffering off;Route by Path or Host
One proxy can serve many apps. Match on a path like /mcp or a hostname to send each request to the right backend.
Hide Your Backend Port
With a proxy, clients only ever see port 443. Your real server port stays private on the internal network, never exposed directly.
Add a Layer of Safety
The proxy is a natural spot for rate limits and request size caps, giving your MCP server a first line of defense. 🛡️
A Clean Separation
Edge concerns live in the proxy; business logic lives in your server. That separation makes both far easier to reason about and change.
Quick Check
What is the main job of TLS termination at the reverse proxy?
Recap: Reverse Proxy
A reverse proxy like Nginx fronts your server: it terminates TLS, forwards requests with proxy_pass, and keeps your backend port private. 🔒
常见问题解答
「在反向代理后运行」课时是免费的吗?
是的 — 「在反向代理后运行」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 MCP Academy 课程的其余内容,请升级到 CoddyKit PRO。 MCP Academy 课程共包含 4 节课。
「在反向代理后运行」这节课中我会学到什么?
终止 TLS,并将 HTTP 路由到您的服务器。 你通过在浏览器中直接运行的动手代码来练习 MCP Academy,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 MCP Academy 需要有经验吗?
无需任何先前经验。CoddyKit 上的 MCP Academy 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 2 节课,共 4 节。
「在反向代理后运行」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 MCP Academy 课中编写并运行代码吗?
能。每节 MCP Academy 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。
此课程中的所有课时
- 将服务器打包进 Docker
- 在反向代理后运行
- 健康检查与重启
- 连接远程客户端