简体   繁体   English

在Azure网站上访问Node.js https应用

[英]access nodejs https app on Azure websites

I deployed my nodejs https server on Azure 我在Azure上部署了NodeJS https服务器

https.createServer(options, app).listen(8080, ()=>{console.log("listening on 8080")}); https.createServer(options,app).listen(8080,()=> {console.log(“正在监听8080”)});;

As you can see from the code snippet above it is listening on port 8080 从上面的代码片段可以看到,它正在侦听端口8080

How should i access my server on Azure websites? 我应该如何访问Azure网站上的服务器?

https://myapp.azurewebsites.net/ or https://myapp.azurewebsites.net:8080/ https://myapp.azurewebsites.net/https://myapp.azurewebsites.net:8080/

Before giving the answer, here are some important concepts you should know about Azure Web App. 在给出答案之前,您需要了解一些有关Azure Web App的重要概念。

  • Azure Web App is a sand box. Azure Web App是一个沙盒。 The only way an Azure web app can be accessed via the internet is through the only two already-exposed HTTP (80) and HTTPS (443) TCP ports. 可以通过Internet访问Azure Web应用程序的唯一方法是仅通过两个已经公开的HTTP(80)和HTTPS(443)TCP端口。
  • For Nodejs App deployed to Azure, Azure will create a named pipe for your server to listen, and pass the request from 443 port(as you use https) to the named pipe. 对于部署到Azure的Nodejs App,Azure将创建一个命名管道供您的服务器侦听,并将请求从443端口(使用https时)传递到该命名管道。 Specific port(even though you use 443) in your nodejs app is invalid and will cause Server Internal Error(500). nodejs应用程序中的特定端口(即使您使用443)也无效,并且会导致服务器内部错误(500)。

So you are supposed to use process.env.PORT instead of 8080 and access your site with the url https://myapp.azurewebsites.net . 因此,您应该使用process.env.PORT而不是8080并使用URL https://myapp.azurewebsites.net访问您的站点。 You can see the pipe if you output it in log. 如果您在日志中输出管道,则可以看到它。

More details about Azure Web App sandbox . 有关Azure Web App沙箱的更多详细信息。

Besides, you can refer to this nodejs web app deploy tutorial and this app sample . 此外,您可以参考此nodejs Web应用程序部署教程此应用程序样本

ok i found https://docs.microsoft.com/en-gb/azure/cloud-services/cloud-services-configure-ssl-certificate-portal 好的,我找到了https://docs.microsoft.com/en-gb/azure/cloud-services/cloud-services-configure-ssl-certificate-portal

it seems that azure handles https 似乎azure处理https

so there is no need for 所以没有必要

https.createServer(options, app).listen(8080, ()=>{console.log("listening on 8080")}); https.createServer(options,app).listen(8080,()=> {console.log(“正在监听8080”)});;

just the standard 只是标准

app.listen(process.env.port) app.listen(process.env.port)

process.env.port is the azure provided port process.env.port是Azure提供的端口

also to set to use https only (that is all incoming http gets redirected to https) refer to 也可以设置为仅使用https(即所有传入的http都重定向到https)是指

https://blogs.msdn.microsoft.com/benjaminperkins/2017/11/30/how-to-make-an-azure-app-service-https-only/ https://blogs.msdn.microsoft.com/benjaminperkins/2017/11/30/how-to-make-an-azure-app-service-https-only/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM