本文介绍了Nestjs到Azure Windows应用程序服务-web.config设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从昨天开始,我一直在尝试将nestjs api部署到azure,但没有成功.最初,我试图将其推向linux云服务计划,并能够通过vs代码进行部署,在azure日志中看到该应用程序已成功启动,但在经过一些挖掘后,它不会从我的端点返回任何数据,我一直看到一些容器故障.我尝试了一段时间的故障排除,然后决定尝试在Windows应用程序服务上进行设置.

I've been trying to deploy my nestjs api to azure since yesterday and have not been successful. At first I was trying to push it to a linux cloud service plan and was able to deploy it from vs code, see in the azure logs that the app was successfully started, but it would not return any data from my endpoints and after some digging, I kept seeing some container failures. I tried troubleshooting that for a while then decided I would try setting it up on a windows app service instead.

遵循本指南: https://docs.microsoft.com/zh-cn/azure/app-service/app-service-web-get-started-nodejs ,我将nestjs应用程序推送到Windows上的Azure应用程序服务再一次,它没有用.我在那篇文章中删除了回购协议,以将其与我的回购进行比较,他们在web.config中为nodejs应用程序指向index.js的入口.该index.js在我的nestjs应用程序中不存在,我进行了一些研究,发现在编译完所有内容后,nestjs应用程序的入口点就是main.js.该示例项目与我的nestjs应用程序的另一个不同之处在于,nestjs应用程序的main.js文件似乎位于dist文件夹中,而不是位于wwwroot路径的根目录中.

Following this guide: https://docs.microsoft.com/en-us/azure/app-service/app-service-web-get-started-nodejs, I pushed my nestjs app up to an azure app service on windows and again, it did not work. I pulled down the repo in that article to compare it to mine and they have the entry point in the web.config for the nodejs app pointing to index.js. That index.js doesn't exist in my nestjs app and I did some research and found out that the entry point for a nestjs app after everything is compiled is main.js. There is another difference in that sample project and my nestjs app in that the nestjs app's main.js file appears to be in a dist folder, rather than at the root of the wwwroot path.

我的nestjs应用程序显然没有包含开箱即用的web.config,因此我以hello world repo的示例创建了一个web.config.我将iisnode路径更新为dist/main.js,并将重写路径也更新为相同的路径/文件,因为这是我唯一想做的事情.

My nestjs app obviously didn't contain a web.config out of the box so I created one using the hello world repo's as an example. I updated the iisnode path to dist/main.js and the rewrite path as well to the same path/file since that's the only thing I can think to do.

唯一的通配符是我正在天蓝色更改的WEBSITE_NODE_DEFAULT_VERSION应用程序设置的节点版本号...我不确定应为我的nestjs应用程序使用什么版本.我当前的本地版本是12.16.2,但是当我将版本更改为Azure时,它不起作用.

The only other wildcard is the node version number that I'm changing in azure for the WEBSITE_NODE_DEFAULT_VERSION application setting...I'm not sure what that should be for my nestjs app. My current local version is 12.16.2 but when I change the version to that on azure, it doesn't work.

我不确定在这里还有什么尝试-如果可以解决Docker容器问题,我可以尝试回到linux,但那似乎是一个死胡同.我想,如果我能使此web.config/version正常工作,我可能会继续沿Windows路线走运.

I'm not sure what else to try here - I'd be fine trying to go back to linux if I could sort out the docker container issue but that seemed like a dead end. I think I'll likely have more luck continuing down the windows route if I can just get this web.config / version thing to work.

main.js是否在dist文件夹中,我应该将web.config指向该文件夹? azure是否有最大版本限制?还有其他我可能会想念的东西吗?

Is main.js in the dist folder where I should be pointing my web.config? Is there a max version limit on azure? Is there anything else I might be missing?

打开流式日志后-我现在看到此异常

After turning on streaming logs - I'm now seeing this exception

经过一番谷歌搜索后,我发现该异常在较旧版本的节点(< 4)中很常见.我已经远远超出了那个版本,并且已经将天蓝色设置为远远超出了那个版本.

after some googling, I've found that exception was common with older versions of node (< 4). I'm well beyond that version and have azure set to a version well beyond that as well.

推荐答案

我在朋友的帮助下整理了一下.在azure cli中运行此命令,可以使用linux安装程序解决所有问题.

I got it sorted out with the help of a friend. Running this in the azure cli got things sorted out using the linux setup.

az webapp config set --resource-group myResourceGroup --name myAppServiceName --startup-file "npm run start:prod"

这篇关于Nestjs到Azure Windows应用程序服务-web.config设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 22:26