Ubuntu 无法绑定到地址 http://127.0.0.1:5000

Ubuntu 无法绑定到地址 http://127.0.0.1:5000

将 aspnetcore 6 web 应用程序部署到 Ubuntu 20.04。这是一篇关于我正在做的事情的文章 https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-apache?view=aspnetcore-6.0#publish-and-copy-over-the-app

Apache 现已设置为将对 的请求转发http://localhost:80到在 运行的 ASP.NET Core 应用程序http://127.0.0.1:5000。它以前可以正常工作,但现在却出现此错误。

 dotnet helloapp.dll
Unhandled exception. System.IO.IOException: Failed to bind to address http://127.0.0.1:5000: address already in use.
 ---> Microsoft.AspNetCore.Connections.AddressInUseException: Address already in use
 ---> System.Net.Sockets.SocketException (98): Address already in use

My service file looks something like
[Unit]
Description=Example .NET Web API App running on Ubuntu

[Service]
WorkingDirectory=/var/www/helloapp
ExecStart=/usr/local/bin/dotnet /var/www/helloapp/helloapp.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-example
User=apache
Environment=ASPNETCORE_ENVIRONMENT=Production 

[Install]
WantedBy=multi-user.target

并配置如下

<VirtualHost *:80>
    ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:5000/
    ProxyPassReverse / http://127.0.0.1:5000/
    ServerName www.example.com
    ServerAlias *.example.com
    ErrorLog ${APACHE_LOG_DIR}helloapp-error.log
    CustomLog ${APACHE_LOG_DIR}helloapp-access.log common
</VirtualHost>

答案1

AddressInUseException按照列出的步骤解决了(在我的例子中是 5001)这里

如果问题仍然存在,请告诉我。

相关内容