# Caddy Proxying

As Strapi does not handle SSL directly and hosting a Node.js service on the "edge" network is not a secure solution it is recommended that you use some sort of proxy application such as Nginx, Apache, HAProxy, Traefik, or others. Below you will find some sample configurations for Caddy, naturally these configs may not suit all environments and you will likely need to adjust them to fit your needs.

Caddy has some very easy to use options relating to Let's encrypt and automated SSL certificate issuing/renewing, while it is certainly the "newer" web server market, it is quickly becoming a great "non-technical" user application for proxying. Please do note that Caddy is still very much in development and as such is evolving often, this guide is based on Caddy v2.0.0.

# Configuration

The below configuration is based on "Caddy File" type, this is a single file configuration that Caddy will use to run the web server. There are multiple other options such as the Caddy REST API that this guide will not cover, you should review the Caddy documentation (opens new window) for further information on alternatives. You can also visit the Caddy Community (opens new window) to speak with others relating to configuration questions.

# Strapi 服务

为了充分利用代理的 Strapi 应用程序,应该配置 Strapi,使其能够识别上游代理。与以下配置一样,有3个匹配的示例。其他信息可以在 服务器配置管理配置 文档中找到。

✏️ NOTE

这些示例使用默认的 API 前缀 /api. 这可以更改,而无需直接修改 Nginx 配置 (请参阅 API prefix 文档).

✋ CAUTION

如果在 ./config/admin.js./config/server.js 文件中更改了 url 键,则需要使用 yarn buildnpm run build 重新构建管理面板。

# Caddy file

The Caddyfile is a convenient Caddy configuration format for humans. It is most people's favorite way to use Caddy because it is easy to write, easy to understand, and expressive enough for most use cases.

In the below examples you will need to replace your domain, and should you wish to use SSL you will need to tweak these Caddy file configs to suit your needs, SSL is not covered in this guide and you should review the Caddy documentation.

Below are 3 example Caddy configurations:

  • Subdomain-based such as api.example.com
  • Subfolder-based with both the API and Admin on the same subfolder (e.g. example.com/test/api and example.com/test/admin)
  • Subfolder-based with split API and admin panel (e.g. example.com/api and example.com/dashboard)

# 将主页重定向到管理面板

如果您不希望将默认的首页挂载在 / 上,则可以使用下面的示例代码创建自定义的 ./public/index.html,以自动重定向到您的管理面板。

✋ CAUTION

此示例配置要求可在 /admin 上访问管理面板。如果您使用上述配置之一将其更改为 /dashboard,则还需要调整此示例配置。

Path — ./public/index.html

<html>
  <head>
    <meta http-equiv="refresh" content="0;URL='/admin'" />
  </head>
</html>