简体   繁体   中英

access nodejs https app on Azure websites

I deployed my nodejs https server on Azure

https.createServer(options, app).listen(8080, ()=>{console.log("listening on 8080")});

As you can see from the code snippet above it is listening on port 8080

How should i access my server on Azure websites?

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

Before giving the answer, here are some important concepts you should know about Azure Web App.

  • Azure Web App is a sand box. 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.
  • 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. Specific port(even though you use 443) in your nodejs app is invalid and will cause Server Internal Error(500).

So you are supposed to use process.env.PORT instead of 8080 and access your site with the url https://myapp.azurewebsites.net . You can see the pipe if you output it in log.

More details about Azure Web App sandbox .

Besides, you can refer to this nodejs web app deploy tutorial and this app sample .

ok i found https://docs.microsoft.com/en-gb/azure/cloud-services/cloud-services-configure-ssl-certificate-portal

it seems that azure handles https

so there is no need for

https.createServer(options, app).listen(8080, ()=>{console.log("listening on 8080")});

just the standard

app.listen(process.env.port)

process.env.port is the azure provided port

also to set to use https only (that is all incoming http gets redirected to https) refer to

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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