无法使用Azure Pipleline在应用程序服务上部署NextJS应用程序
我尝试使用Azure Pipeline将NextJS应用程序调整为AppService。第一个构建阶段和部署阶段。但是,当我在应用服务上转到console
时,它不会创建web.config,当我访问URL时,它显示了类似的文本,例如:“ 您无权查看此目录或页面。” 我的应用程序在本地完美工作。
我做错了什么步骤?请帮助我,谢谢。
配置: AppService:OS-Windows,节点16 / 代理:OS Windows
# Node.js with React
# Build a Node.js project that uses React.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/javascript
trigger:
branches:
include:
- master
- releases/*
- develop
pool: 'window-agent-fe'
stages:
- stage: BuildStage
jobs:
- job: BuildJob
steps:
- task: CmdLine@2
displayName: 'Instal Zip file Supported'
inputs:
script: 'sudo apt-get -y install zip'
- task: NodeTool@0
inputs:
versionSpec: '16.x'
checkLatest: true
displayName: 'Install Node.js'
- script: npm i --force
displayName: 'Install Node Packages'
- script: npm run lint
displayName: Lint
- script: npm run build
displayName: 'Build'
- task: ArchiveFiles@2
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)/.next/'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
replaceExistingArchive: true
verbose: true
- publish: "$(Build.ArtifactStagingDirectory)"
artifact: package
- stage: 'DeployStage'
dependsOn: BuildStage
condition: succeeded()
jobs:
- deployment: 'DevDeployJob'
environment: DEV
strategy:
runOnce:
deploy:
steps:
- download: current
displayName: Download build file
artifact: package
- task: AzureRmWebAppDeployment@4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: '***********'
appType: 'webApp'
WebAppName: 'fpt-capstone-client'
packageForLinux: '$(System.WorkFolder)/1/package/$(Build.BuildId).zip'
I try to depoyed nextjs app to appservice using azure pipeline. First Build Stage and Deploy stage are worked. But when I go to console
on app service, it don't create web.config and when I access the url it shows text like: "You do not have permission to view this directory or page."
My app work perfectly on Local.
Is there any steps I do wrong? Please help me,thank you.
Configuration:
appservice: OS-Windows, Node 16 /
Agents: OS Windows
# Node.js with React
# Build a Node.js project that uses React.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/javascript
trigger:
branches:
include:
- master
- releases/*
- develop
pool: 'window-agent-fe'
stages:
- stage: BuildStage
jobs:
- job: BuildJob
steps:
- task: CmdLine@2
displayName: 'Instal Zip file Supported'
inputs:
script: 'sudo apt-get -y install zip'
- task: NodeTool@0
inputs:
versionSpec: '16.x'
checkLatest: true
displayName: 'Install Node.js'
- script: npm i --force
displayName: 'Install Node Packages'
- script: npm run lint
displayName: Lint
- script: npm run build
displayName: 'Build'
- task: ArchiveFiles@2
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)/.next/'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
replaceExistingArchive: true
verbose: true
- publish: "$(Build.ArtifactStagingDirectory)"
artifact: package
- stage: 'DeployStage'
dependsOn: BuildStage
condition: succeeded()
jobs:
- deployment: 'DevDeployJob'
environment: DEV
strategy:
runOnce:
deploy:
steps:
- download: current
displayName: Download build file
artifact: package
- task: AzureRmWebAppDeployment@4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: '***********'
appType: 'webApp'
WebAppName: 'fpt-capstone-client'
packageForLinux: '$(System.WorkFolder)/1/package/$(Build.BuildId).zip'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
img src =“ https://i.sstatic.net/kcwov.png” alt =“ alt =“ enter image description”>在这里
< 解决问题以解决问题:
问题发生了,因为如果我们没有添加任何 server.js 或 web.config 文件。
在您的 package.json 文件中,请确保添加以下代码。
而不是上面您可以使用以下。
在部署您的 nextjs 应用程序中,

web.config
root目录中的文件。请参阅在这里在您的 server.js 文件中,如果您正在使用
此尝试像以下
那样更改它
如果在Azure App服务中部署后仍面临问题。尝试更改您的 虚拟应用程序和目录

物理路径
喜欢\ site \ site \ wwwroot \ wwwroot \
进入您的某些着陆页,例如\ site \ wwwroot \ pages \ index.html
Follow workaround to fix the issue:
The issue happens because of if we not added any of the server.js or web.config files.
In your package.json file make sure to add the below line of code.
Instead of above you can use the below.
While deploying your nextjs application into azure you have to add the

web.config
file in root directory. Refer hereIn your Server.js file if you are using
this try to change it like below
If still you are facing the issue after deployed in a azure app service. Try to change your virtual Applications and Directories

Physical Path
like\site\wwwroot\
into some your landing page like\site\wwwroot\pages\index.html
Reference