首页 > 解决方案 > 显示 apache 默认页面的 ASP.NET 核心应用程序

问题描述

我一直在关注有关如何在 Ubuntu 20.04 上的 .NET 5 应用程序中安装 ASP.NET Core的博客。当我访问链接api.example.com时,它显示默认的 apache 页面。它应该向我展示 ASP.NET Core 应用程序。

所有应用程序文件都存储在其中,/var/www/api/并且所有权已授予www-data

虚拟主机 api.conf

在 VirtualHost 中,我有以下配置并启用了 conf。

<VirtualHost *:*>
    RequestHeader set "X-Forwarded-Proto" expr=%{REQUEST_SCHEME}
</VirtualHost>

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

添加服务

添加了以下服务配置并启用了服务。

[Unit]
Description=Api

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

[Install]
WantedBy=multi-user.target

当我跑步时,sudo systemctl status api.service我得到以下信息

ubuntu@sandbox:~$ sudo systemctl status api.service
● api.service - Api
     Loaded: loaded (/etc/systemd/system/api.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2021-07-04 12:28:54 UTC; 12h ago
   Main PID: 21133 (dotnet)
      Tasks: 13 (limit: 1116)
     Memory: 33.3M
     CGroup: /system.slice/api.service
             └─21133 /usr/bin/dotnet /var/www/api/Api.dll

Jul 04 12:28:55 sandbox api[21133]: warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
Jul 04 12:28:55 sandbox api[21133]:       No XML encryptor configured. Key {cb00126e-6ce8-41cc-9568-800ff705be3a} may be persisted to storage in unencrypted form.
Jul 04 12:28:55 sandbox api[21133]: info: Microsoft.Hosting.Lifetime[0]
Jul 04 12:28:55 sandbox api[21133]:       Now listening on: http://localhost:5000
Jul 04 12:28:55 sandbox api[21133]: info: Microsoft.Hosting.Lifetime[0]
Jul 04 12:28:55 sandbox api[21133]:       Application started. Press Ctrl+C to shut down.
Jul 04 12:28:55 sandbox api[21133]: info: Microsoft.Hosting.Lifetime[0]
Jul 04 12:28:55 sandbox api[21133]:       Hosting environment: Production
Jul 04 12:28:55 sandbox api[21133]: info: Microsoft.Hosting.Lifetime[0]
Jul 04 12:28:55 sandbox api[21133]:       Content root path: /var/www/api

标签: c#asp.netapacheubuntu-20.04

解决方案


推荐阅读