ASP.NET Core 應用程式回應 503 Service Unavailable on Ubuntu 18.04

ASP.NET Core 應用程式回應 503 Service Unavailable on Ubuntu 18.04

我有一個庫存的、幾乎未修改的 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 服務不可用錯誤。

我的阿帕契配置:

<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 發送的。

修復應用程式的偵聽連接埠。例如,inappsettings.json或 via ASPNETCORE_URLS。有更多資訊可供參考這裡

順便說一下, 中的尾部斜線不符ProxyPass。這可能會導致其他問題。

相關內容