我正在 Azure 应用服务上部署 Strapi 项目。这是我到目前为止所做的:
I deployed the Strapi project using FTP and then ran the necessary commands (npm install, npm run build) in the Azure Kudu console.
After starting the project with npm run develop, the console shows that Strapi started successfully, and it provides a URL like http://localhost:8080/admin.
I also tried deploying the application via GitHub Actions, but the result was the same.
我更新了 Strapi 项目中的 server.js 文件以使用 Azure 默认域名 (.azurewebsites.net) 作为主机,但是当我尝试使用 Azure 默认域通过浏览器访问 Strapi 管理面板时,它确实出现了问题不工作。
我的问题是:
How can I make the Strapi admin panel publicly accessible on Azure App Service?
Do I need to map localhost with the Azure default domain somewhere in the configuration?
有关此问题的任何帮助或指导将不胜感激。
提前谢谢您!
我创建了一个示例 Strapi 应用程序,并通过 GitHub 操作成功将其部署到 Azure Web App。
确保在您的
env
文件中添加发布 URL
HOST=0.0.0.0
PORT=1337
PUBLIC_URL=https://<Azureappservice-domain>.azurewebsites.net
同时在
server.js
文件中添加 PUBLIC_URL
server.js:
export default ({ env }) => ({
host: env('HOST', '0.0.0.0'),
port: env.int('PORT', 1337),
url: env('PUBLIC_URL', 'https://<Azureappservice-domain>.azurewebsites.net')
app: {
keys: env.array('APP_KEYS'),
},
});
将以下启动脚本添加到
package.json
文件中,这有助于执行正确的 Strapi 启动命令来启动应用程序。
"start": "node node_modules/@strapi/strapi/bin/strapi.js start"
完整package.json:
{
"name": "strapisample",
"version": "0.1.0",
"private": true,
"description": "A Strapi application",
"scripts": {
"build": "strapi build",
"deploy": "strapi deploy",
"develop": "strapi develop",
"start": "node node_modules/@strapi/strapi/bin/strapi.js start",
"strapi": "strapi"
},
"dependencies": {
"@strapi/plugin-cloud": "5.8.0",
"@strapi/plugin-users-permissions": "5.8.0",
"@strapi/strapi": "5.8.0",
"better-sqlite3": "11.3.0",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-router-dom": "^6.0.0",
"styled-components": "^6.0.0"
},
"devDependencies": {
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"typescript": "^5"
},
"engines": {
"node": ">=18.0.0 <=22.x.x",
"npm": ">=6.0.0"
},
"strapi": {
"uuid": "8b858a84-0904-4cc4-ae57-38d0cc99d37a"
}
}
pm2 serve /home/site/wwwroot/build --no-daemon --spa
完成上述更改后,我已通过 GitHub 操作成功将应用程序部署到 Azure Web 应用程序。