# HAProxy 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 HAProxy, naturally these configs may not suit all environments and you will likely need to adjust them to fit your needs.

# Configuration

The below examples are acting as an "SSL termination" proxy, meaning that HAProxy is only accepting the requests on SSL and proxying to other backend services such as Strapi or other web servers. HAProxy cannot serve static content and as such it is usually used to handle multi-server deployments in a failover or load-balance situation. The examples provided below are based around everything existing on the same server, but could easily be tweaked for multi-server deployments.

# Strapi 服务

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


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


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

# HAProxy

The following examples are either proxying all requests directly to Strapi or are splitting requests between Strapi and some other backend web server such as Nginx, Apache, or others.

Below are 3 example HAProxy configurations:

  • Sub-domain based such as api.example.com
  • subfolder based with both the API and Admin on the same subfolder such as example.com/test/api and example.com/test/admin
  • subfolder based with split API and Admin such as example.com/api and example.com/dashboard

✋ HAProxy SSL Support

If you are not familiar with HAProxy and using SSL certificates on the bind directive, you should combine your SSL cert, key, and any CA files into a single .pem package and use it's path in the bind directive. For more information see HAProxy's bind documentation (opens new window). Most Let's Encrypt clients do not generate a file like this so you may need custom "after issue" scripts to do this for you.

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

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


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

Path — ./public/index.html

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