我有一个几乎未经修改的 Visual Studio 模板 ASP.NET Core 应用程序,我正尝试在 Ubuntu 18.04 上运行。我遵循了以下指南:https://docs.microsoft.com/en-gb/aspnet/core/host-and-deploy/linux-apache?view=aspnetcore-3.1。
经过一段时间的尝试和失败后,我终于让 ASP.NET 服务运行起来了。但是当我访问我的页面时,我看到了 503 服务不可用错误。
我的 Apache 配置:
<IfModule mod_ssl.c>
<VirtualHost *:80>
ServerName example.com
Redirect / https://example.com
Redirect /panel https://example.com/panel
Redirect /privacy https://example.com/privacy
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
DocumentRoot /var/www/
ServerAdmin [email protected]
RewriteEngine On
ErrorLog "/var/log/apache2/rewrite"
LogLevel alert rewrite:trace6
# ASP.NET application
# launchSettings.json is configured to listen on this port
ProxyPass /panel https://localhost:33138/
ProxyPassReverse /panel https://localhost:33138/
ProxyPass /api/socket ws://localhost:44909/api/socket
ProxyPassReverse /api/socket ws://localhost:44909/api/socket
ProxyPass /pgadmin4 !
ProxyPass /privacy !
ProxyPass /contact !
ProxyPass /panel !
ProxyPass / http://localhost:44909/
ProxyPassReverse / http://localhost:44909/
SSLEngine on
SSLOptions +StrictRequire
SSLProtocol TLSv1
ServerAlias example.com
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
systemctl status tpanel
这是(我的 ASP 守护进程)的结果:
● tpanel.service - a .NET Core 3.1 server
Loaded: loaded (/etc/systemd/system/tpanel.service; disabled; vendor preset: enabled)
Active: active (running) since Fri 2019-12-13 10:16:21 CET; 4h 1min ago
Main PID: 2765 (dotnet)
Tasks: 16 (limit: 4915)
CGroup: /system.slice/tpanel.service
└─2765 /usr/bin/dotnet /var/www/TPanel/publish/TPanel.dll
Dec 13 10:16:22 vps-example dotnet[2765]: info: Microsoft.Hosting.Lifetime[0]
Dec 13 10:16:22 vps-example dotnet[2765]: Now listening on: http://localhost:5000
Dec 13 10:16:22 vps-example dotnet[2765]: info: Microsoft.Hosting.Lifetime[0]
Dec 13 10:16:22 vps-example dotnet[2765]: Now listening on: https://localhost:5001
Dec 13 10:16:22 vps-example dotnet[2765]: info: Microsoft.Hosting.Lifetime[0]
Dec 13 10:16:22 vps-example dotnet[2765]: Application started. Press Ctrl+C to shut down.
Dec 13 10:16:22 vps-example dotnet[2765]: info: Microsoft.Hosting.Lifetime[0]
Dec 13 10:16:22 vps-example dotnet[2765]: Hosting environment: Production
Dec 13 10:16:22 vps-example dotnet[2765]: info: Microsoft.Hosting.Lifetime[0]
Dec 13 10:16:22 vps-example dotnet[2765]: Content root path: /var/www/TPanel/publish
launchSettings.json
:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:50015",
"sslPort": 44313
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"TPanel": {
"commandName": "TPanel",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:33138"
}
}
}
但就像我说的,当我访问时,example.com/panel
我看到了 503 错误。我网站的其他部分运行良好。
其他信息:
- 我正在运行另一个不相关的应用程序,该应用程序使用了 5001 端口,但我用其他应用程序替换了它,所以这应该不是问题
- 似乎无论我将应用程序的端口设置为
33138
或 都无关紧要5001
,它都不会改变任何东西
答案1
launchSettings.json
是 VS Code 的东西。它在这里不做任何事情。
您的应用程序正在端口 5000(HTTP)和 5001(HTTPS)上运行,这是我们可以在日志中看到的不可否认的事实:
Dec 13 10:16:22 vps-example dotnet[2765]: info: Microsoft.Hosting.Lifetime[0] Dec 13 10:16:22 vps-example dotnet[2765]: Now listening on: http://localhost:5000 Dec 13 10:16:22 vps-example dotnet[2765]: info: Microsoft.Hosting.Lifetime[0] Dec 13 10:16:22 vps-example dotnet[2765]: Now listening on: https://localhost:5001
Apache 配置为连接到端口 33138 上的应用程序:
ProxyPass /panel https://localhost:33138/ ProxyPassReverse /panel https://localhost:33138/
该应用程序未监听该端口,因此 503 – 由 Apache 发送,而不是 ASP.NET Core。
修复应用程序的监听端口。例如,在appsettings.json
或通过ASPNETCORE_URLS
。更多信息可用这里。
顺便说一句, 中的尾部斜杠不匹配ProxyPass
。这可能会导致其他问题。