Support CDN Configuration
This article explains how to configure the HENGSHI system to achieve the separation of CDN static resources and program configuration. Supported configuration methods:
- Backend Configuration of Frontend CDN Address (Recommended Method)
- Frontend Configuration of Backend API Address
Backend Configuration for Frontend CDN Address (Recommended Method)
In this method, the business domain points to the HENGSHI deployment service, and the browser is instructed to fetch static resource files from the CDN service.
In the example, the backend deployment domain is assumed to be https://bi.domain.com
, and the frontend CDN deployment domain is https://cdn.domain.com
.
CDN Configuration
Supports two methods:
CDN Automatic Proxy
No need to deploy frontend files separately. Set the CDN's origin address tohttps://bi.domain.com
, ensuring that static resource requests are automatically fetched from the origin.Independent Deployment of Frontend Files
The installation package for the corresponding frontend version islhotse-x.y.z-xxx.zip
. After extraction, retain thestatic
directory. Upload the files under thestatic
directory (excluding thestatic
directory itself andstatic/index.html
) to the static file service. These files can then be accessed via CDN proxy or used to distribute static resources to an independent static file server, allowing access through the CDN domain athttps://cdn.domain.com/assets/xxx
.
hengshi Configuration
- hengshi relies on a reverse proxy in front of it. Here, nginx is used as an example. Configure the reverse proxy to pass a header
X-HS-CDN-Path
to the hengshi service, specifying the CDN address.
server {
listen 443 ssl;
server_name bi.domain.com;
...
# Note: The address should end with '/'
proxy_set_header X-HS-CDN-Path "https://cdn.domain.com/"; // [!code focus]
...
}
- Request the hengshi service to verify the configuration. If the configured address is returned, the configuration is successful.
curl https://bi.domain.com | grep -o '<name="cdn" content="https://cdn.domain.com/">'
Access Method
Accessing https://bi.domain.com
via a browser should show that all requests for js and css files are sent to https://cdn.domain.com
, while API requests are still sent to https://bi.domain.com
.
Frontend Configuration for Backend API Address
In this approach, the business domain points to the CDN service, and the frontend either directly accesses the backend API or indirectly accesses the HENGSHI backend API through the CDN.
In the example, it is assumed that the backend deployment domain is https://api.domain.com
, and the frontend CDN deployment domain is https://cdn.domain.com
.
CDN Configuration
- The installation package for the corresponding front-end version is
lhotse-x.y.z-xxx.zip
. After extracting, retain thestatic
directory. - Configure the backend domain in the front-end
static/index.html
file.shcd static; sed -i -r 's#backend=\{api:"[^"]*"\}#backend=\{api:"https://api.domain.com"\}#' index.html
- Deploy
index.html
andassets
under thestatic
directory to the root path of the CDN, so that the CDN domain can accesshttps://cdn.domain.com/index.html
andhttps://cdn.domain.com/assets/xxx
.
hengshi Configuration
- Configure the frontend CDN domain name in the backend configuration file (assuming the backend is deployed at
/opt/hengshi
). Add the variableexport ACCESS_CONTROL_ALLOW_ORIGIN="https://cdn.domain.com"
to/opt/hengshi/conf/hengshi-sense-env.sh
. - Restart the hengshi service.sh
cd /opt/hengshi; bin/hengshi-sense-bin restart hengshi;
Access Method
Access the CDN frontend domain via a browser at https://cdn.domain.com
. You should see all JS and CSS file requests sent to https://cdn.domain.com
, and API requests sent to https://api.domain.com
.