大佬教程收集整理的这篇文章主要介绍了Azure Web 应用程序 Node.js 部署后返回 404,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
最近几天我一直被这个问题困扰。我正在尝试将带有服务器端渲染的 nuxt 应用程序部署到 Azure Web 应用程序,但是当部署完成时,该应用程序返回 404。
这是我的 github 操作脚本:
name: Build and deploy Node.Js app to Azure Web App - mercado-digital-staging
on:
push:
branches:
- master
workflow_dispatch:
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Set up Node.Js version
uses: actions/setup-node@v1
with:
node-version: '14.x'
- name: npm install,build,and test
run: |
npm install
npm run build --if-present
npm run test --if-present
- name: copy files
run: |
mkdir server
mkdir server\.nuxt
mkdir server\static
copy-Item -Path .\.nuxt\* -DesTination .\server\.nuxt -Recurse -Force
copy-Item -Path .\static\* -DesTination .\server\static -Recurse -Force
copy-Item -Path .\nuxt.config.js -DesTination .\server -Force
copy-Item -Path .\package.Json -DesTination .\server -Force
copy-Item -Path .\package-lock.Json -DesTination .\server -Force
Move-Item -Path .\static\web.config -DesTination .\server\ -Force
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v2
with:
name: node-app
path: .\server
deploy:
runs-on: windows-latest
needs: build
environment:
name: 'production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v2
with:
name: node-app
- name: npm install
run: |
npm uninstall nuxt
npm install nuxt-start
npm i --production
- name: 'Deploy to Azure Web App'
ID: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: 'mercado-digital-staging'
slot-name: 'production'
publish-profile: ${{ secrets.AzureAppservice_PublishProfile_eb3443a52796493d9744aa0c55879c5b }}
package: .\
我在网络应用程序中的 wwwroot:
web.confg
<configuration>
<system.webServer>
<!-- Visit https://azure.microsoft.com/en-us/blog/introduction-to-websockets-on-windows-azure-web-sites/ for more information on WebSocket support -->
<webSocket enabled="false" />
<handlers>
<!-- InDicates that the server.Js file is a Node.Js site to be handled by the IIsnode module -->
<add name="IIsnode" path=".nuxt/server" verb="*" modules="IIsnode"/>
</handlers>
<rewrite>
<rules>
<!-- Do not interfere with requests for node-inspector deBUGging -->
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^server\/deBUG[\/]?" />
</rule>
<!-- First we consIDer whether the incoming URL matches a physical file in the /public folder -->
<rule name="StaticContent">
<action type="Rewrite" url="public{requEST_URI}"/>
</rule>
<!-- All other URLs are mapped to the Node.Js site entry point -->
<rule name="DynamicContent">
<conditions>
<add input="{requEST_filename}" matchType="Isfile" negate="True"/>
</conditions>
<action type="Rewrite" url="server"/>
</rule>
</rules>
</rewrite>
<!-- 'bin' directory has no special meaning in Node.Js and apps can be placed in it -->
<security>
<requestfiltering>
<hIDdenSegments>
<remove segment="bin"/>
</hIDdenSegments>
</requestfiltering>
</security>
<!-- Make sure error responses are left untouched -->
<httpErrors exisTingResponse="Passthrough" />
<IIsnode nodeProcessCommandline="npm start" watchedfiles="web.config;*.Js" deBUGgingEnabled="false" />
<!--
You can control how Node is hosted within IIS using the following options:
* watchedfiles: semi-colon separated List of files that will be watched for changes to restart the server
* node_env: will be propagated to node as NODE_ENV environment variable
* deBUGgingEnabled - controls whether the built-in deBUGger is enabled
See https://github.com/tjanczuk/IIsnode/blob/master/src/samples/configuration/web.config for a full List of options
-->
<!--<IIsnode watchedfiles="web.config;*.Js"/>-->
<staticContent><mimeMap fileExtension=".Json" mimeType="application/Json" /></staticContent>
</system.webServer>
</configuration>
package.Json
{
"name": "mercado-digital","version": "1.0.0","private": true,"scripts": {
"dev": "nuxt","build": "nuxt build","start": "nuxt-start","generate": "nuxt generate","lint:Js": "eslint --ext \".Js,.vue\" --ignore-path .gitignore .","lint": "npm run lint:Js"
},"ENGInes": {
"node": ">=8.17","npm": ">=6.13.4"
},"dependencIEs": {
"@nuxtJs/axios": "^5.13.1","@nuxtJs/vuetify": "^1.11.3","core-Js": "^3.9.1","nuxt-start": "^2.15.7","oIDc-clIEnt": "^1.11.5"
},"devDependencIEs": {
"@nuxt/types": "^2.15.3","@nuxt/typescript-build": "^2.1.0","@nuxtJs/device": "^2.1.0","@nuxtJs/eslint-config-typescript": "^6.0.0","@nuxtJs/eslint-module": "^3.0.2","babel-eslint": "^10.1.0","eslint": "^7.22.0","eslint-plugin-nuxt": "^2.0.0","eslint-plugin-vue": "^7.7.0"
}
}
应用设置: WEBSITE_NODE_DEFAulT_VERSION:~14
应用的网址: https://mercado-digital-staging.azurewebsites.net/
有没有办法调试这个或获取启动日志?如果您需要其他任何东西,请告诉我。提前感谢您的帮助!
我认为下面是错误的。
"start": "nuxt-start",
应该是
"start": "nuxt start",
另外,你的web.config文件,我看着有点奇怪,不知道能不能正常运行。如果可以,那是最好的。如果还是不行,可以参考之前正常运行的web.config文件格式进行调整。
you can download my web.config
from github.
以上是大佬教程为你收集整理的Azure Web 应用程序 Node.js 部署后返回 404全部内容,希望文章能够帮你解决Azure Web 应用程序 Node.js 部署后返回 404所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。