小编Ame*_*liu的帖子

在 Heroku 上为仅侦听 https 的服务使用哪个环境变量

我正在使用将部署在 Heroku 上的 AspNet 核心设置一个仅限 https 的 Web API 服务。部署是通过 docker 完成的,所以我配置了一个 Dockerfile。但是,每当我部署到 Heroku 时,都会收到与 https 端口绑定相关的错误。我想知道 Heroku 是否为 https 提供了一个特殊的 env 变量,服务可以在其中绑定以指定服务应该侦听的 https 端口。

AspNet 核心提供 2 个环境变量ASPNETCORE_HTTPS_PORT=5001ASPNETCORE_URLS=https://*:5001其中可以指定服务应侦听的 https 端口。

但是由于 Heroku 不允许 Web 进程手动指定它应该侦听的端口,因此它们提供了一个 Web 应用程序可以绑定到的 PORT 环境变量。

我试过使用ASPNETCORE_HTTPS_PORT=$PORTand ASPNETCORE_URLS=https://*:$PORT,但出现以下错误:

crit: Microsoft.AspNetCore.Server.Kestrel[0]
Unable to start Kestrel.
System.Net.Sockets.SocketException (13): Permission denied at System.Net.Sockets.Socket.UpdateStatusAfterSocketErrorAndThrowException(SocketError error, String callerName) 
at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.Sockets.Socket.Bind(EndPoint localEP)
at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketConnectionListener.Bind()
at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketTransportFactory.BindAsync(EndPoint endpoint, CancellationToken cancellationToken)
at …
Run Code Online (Sandbox Code Playgroud)

c# heroku asp.net-core

3
推荐指数
1
解决办法
578
查看次数

标签 统计

asp.net-core ×1

c# ×1

heroku ×1