gpt4 book ai didi

linux - 带 SSL 的 Linux 服务中的 .Net Core 2.2 API

转载 作者:太空宇宙 更新时间:2023-11-04 11:47:40 25 4
gpt4 key购买 nike

我有一个 .Net Core 2.2 API,它已经过测试并且在从 linux 命令 shell (Ubuntu 16.04) 启动时可以正常工作,但是当作为服务运行时,仅绑定(bind) http,而不绑定(bind) https。我知道这更有可能是因为需要告知服务环境有关 SSL 的信息,但我没有在服务单元文件中找到有关如何设置它的任何信息。任何帮助将不胜感激。

服务单元文件:

[Unit]
Description=Authentication .NET Web API App running on CentOS 7

[Service]
WorkingDirectory=/var/www/Authentication
ExecStart=/usr/share/dotnet/dotnet /var/www/Authentication/Authentication.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-authentication
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production

[Install]
WantedBy=multi-user.target

控制台输出:

warn: Microsoft.AspNetCore.Server.Kestrel[0]
Unable to bind to http://localhost:5000 on the IPv6 loopback interface: 'Cannot assign requested address'.
warn: Microsoft.AspNetCore.Server.Kestrel[0]
Unable to bind to https://localhost:5001 on the IPv6 loopback interface: 'Cannot assign requested address'.
Hosting environment: Production
Content root path: /var/www/Authentication
Now listening on: http://localhost:5000
Now listening on: https://localhost:5001
Application started. Press Ctrl+C to shut down.

服务状态:

● Authentication.service - Authentication .NET Web API App running on CentOS 7
Loaded: loaded (/etc/systemd/system/Authentication.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2019-07-22 06:48:36 CDT; 38min ago
Main PID: 11506 (dotnet)
CGroup: /system.slice/Authentication.service
└─11506 /usr/share/dotnet/dotnet /var/www/Authentication/Authentication.dll

Jul 22 06:48:38 Chris-PC dotnet-authentication[11506]: warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[59]
Jul 22 06:48:38 Chris-PC dotnet-authentication[11506]: Neither user profile nor HKLM registry available. Using an ephemeral key repository. Protected data will be unavailable when application exits.
Jul 22 06:48:38 Chris-PC dotnet-authentication[11506]: warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
Jul 22 06:48:38 Chris-PC dotnet-authentication[11506]: No XML encryptor configured. Key {bc217aa5-1a54-4033-bcb3-0d1bd39cf425} may be persisted to storage in unencrypted form.
Jul 22 06:48:40 Chris-PC dotnet-authentication[11506]: warn: Microsoft.AspNetCore.Server.Kestrel[0]
Jul 22 06:48:40 Chris-PC dotnet-authentication[11506]: Unable to bind to http://localhost:5000 on the IPv6 loopback interface: 'Cannot assign requested address'.
Jul 22 06:48:40 Chris-PC dotnet-authentication[11506]: Hosting environment: Production
Jul 22 06:48:40 Chris-PC dotnet-authentication[11506]: Content root path: /var/www/Authentication
Jul 22 06:48:40 Chris-PC dotnet-authentication[11506]: Now listening on: http://localhost:5000
Jul 22 06:48:40 Chris-PC dotnet-authentication[11506]: Application started. Press Ctrl+C to shut down.

journalctl 输出:

Jul 22 06:48:36 Chris-PC systemd[1]: Started Authentication .NET Web API App running on CentOS 7.
Jul 22 06:48:38 Chris-PC dotnet-authentication[11506]: : Microsoft.AspNetCore.DataProtection.Repositories.EphemeralXmlRepository[50]
Jul 22 06:48:38 Chris-PC dotnet-authentication[11506]: Using an in-memory repository. Keys will not be persisted to storage.
Jul 22 06:48:38 Chris-PC dotnet-authentication[11506]: warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[59]
Jul 22 06:48:38 Chris-PC dotnet-authentication[11506]: Neither user profile nor HKLM registry available. Using an ephemeral key repository. Protected data will be unavailable when application exits.
Jul 22 06:48:38 Chris-PC dotnet-authentication[11506]: warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
Jul 22 06:48:38 Chris-PC dotnet-authentication[11506]: No XML encryptor configured. Key {bc217aa5-1a54-4033-bcb3-0d1bd39cf425} may be persisted to storage in unencrypted form.
Jul 22 06:48:40 Chris-PC dotnet-authentication[11506]: warn: Microsoft.AspNetCore.Server.Kestrel[0]
Jul 22 06:48:40 Chris-PC dotnet-authentication[11506]: Unable to bind to http://localhost:5000 on the IPv6 loopback interface: 'Cannot assign requested address'.
Jul 22 06:48:40 Chris-PC dotnet-authentication[11506]: Hosting environment: Production
Jul 22 06:48:40 Chris-PC dotnet-authentication[11506]: Content root path: /var/www/Authentication
Jul 22 06:48:40 Chris-PC dotnet-authentication[11506]: Now listening on: http://localhost:5000
Jul 22 06:48:40 Chris-PC dotnet-authentication[11506]: Application started. Press Ctrl+C to shut down.

最佳答案

发现问题与 www-data 用户 ID 有关。如果我编辑服务单元以使用我的 id(id 在命令 shell 下运行),那么 http 和 https 都会被绑定(bind)。需要弄清楚与 www-data 有什么不同。

系统状态:

● Authentication.service - Authentication .NET Web API App running on CentOS 7
Loaded: loaded (/etc/systemd/system/Authentication.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2019-07-22 08:17:05 CDT; 8min ago
Main PID: 19440 (dotnet)
CGroup: /system.slice/Authentication.service
└─19440 /usr/share/dotnet/dotnet /var/www/Authentication/Authentication.dll

Jul 22 08:17:05 Chris-PC systemd[1]: Started Authentication .NET Web API App running on CentOS 7.
Jul 22 08:17:10 Chris-PC dotnet-authentication[19440]: warn: Microsoft.AspNetCore.Server.Kestrel[0]
Jul 22 08:17:10 Chris-PC dotnet-authentication[19440]: Unable to bind to http://localhost:5000 on the IPv6 loopback interface: 'Cannot assign requested address'.
Jul 22 08:17:11 Chris-PC dotnet-authentication[19440]: warn: Microsoft.AspNetCore.Server.Kestrel[0]
Jul 22 08:17:11 Chris-PC dotnet-authentication[19440]: Unable to bind to https://localhost:5001 on the IPv6 loopback interface: 'Cannot assign requested address'.
Jul 22 08:17:11 Chris-PC dotnet-authentication[19440]: Hosting environment: Production
Jul 22 08:17:11 Chris-PC dotnet-authentication[19440]: Content root path: /var/www/Authentication
Jul 22 08:17:11 Chris-PC dotnet-authentication[19440]: Now listening on: http://localhost:5000
Jul 22 08:17:11 Chris-PC dotnet-authentication[19440]: Now listening on: https://localhost:5001
Jul 22 08:17:11 Chris-PC dotnet-authentication[19440]: Application started. Press Ctrl+C to shut down.

关于linux - 带 SSL 的 Linux 服务中的 .Net Core 2.2 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57145474/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com