.NET Core 3.1 Ubuntu 503 服务不可用/AH01114 无法连接到后端(端口 5000)

.NET Core 3.1 Ubuntu 503 service unavailable / AH01114 failed to make connection to backend (port 5000)

我使用 Visual Studio 在 Windows 盒子上创建了一个 .NET Core 3.1 应用程序。我使用基本的文件复制命令将它部署到 Ubuntu 18.04 服务器。一切都很好,应用程序运行良好。

然后我在 Ubuntu 盒子本身上发布了应用程序(CI 使用 Bamboo 的项目)。应用程序没有响应(给出 503 服务不可用)。日志文件抱怨 AH01114:HTTP:无法连接到后端:127.0.0.1.

经过一些研究,我 运行 net stat --tcp --listen --numeric ports 使用 Visual Studio 构建版本和 Ubuntu dotnet publish 版本。结果显示 localhost:5000 正在使用 Visual Studio(工作)内置版本收听。

daniel@ubuntu-sandbox:~$ netstat --tcp --listen --numeric-ports
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 localhost:53            0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 localhost:33060         0.0.0.0:*               LISTEN     
tcp        0      0 localhost:5000          0.0.0.0:*               LISTEN     
tcp        0      0 localhost:3306          0.0.0.0:*               LISTEN     
tcp6       0      0 [::]:80                 [::]:*                  LISTEN     
tcp6       0      0 [::]:22                 [::]:*                  LISTEN     
tcp6       0      0 ip6-localhost:5000      [::]:*                  LISTEN     

daniel@ubuntu-sandbox:~$ netstat --tcp --listen --numeric-ports
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 localhost:53            0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 localhost:33060         0.0.0.0:*               LISTEN     
tcp        0      0 localhost:3306          0.0.0.0:*               LISTEN     
tcp6       0      0 [::]:80                 [::]:*                  LISTEN     
tcp6       0      0 [::]:22                 [::]:*                  LISTEN     
daniel@ubuntu-sandbox:~$ 

我查看了我的(香草)netcore.conf Apache 文件:

daniel@ubuntu-sandbox:~$ cat /etc/apache2/conf-enabled/netcore.conf
<VirtualHost *:80>  
   ServerName www.DOMAIN.COM  
   ProxyPreserveHost On  
   ProxyPass / http://127.0.0.1:5000/  
   ProxyPassReverse / http://127.0.0.1:5000/  
   RewriteEngine on  
   RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]  
   RewriteCond %{HTTP:CONNECTION} Upgrade$ [NC]  
   RewriteRule /(.*) ws://127.0.0.1:5000/ [P]  
   ErrorLog /var/log/apache2/netcore-error.log  
   CustomLog /var/log/apache2/netcore-access.log common  
</VirtualHost> 

果然,有 5000 个。

如何解决这个问题?我缺少证书吗? Visual Studio 是否在其构建中嵌入了一个开发人员,而我在 Ubuntu 盒子上构建它时却没有?

我解决了这个特殊问题。对于那些遇到类似问题的人,这是我所做的。

tl;博士;答案:

更新文件的文件权限post编译:

sudo chmod 664 -R /var/netcore/* && sudo chmod 771 /var/netcore

更详细的解释我是如何诊断的:

sudo journalctl -fu YOUR_DOTNET_CORE_APPNAME_HERE.service

这表明我的 dll 访问被拒绝。我将这些文件的权限与 Visual Studio 构建所做的权限进行了比较,将它们匹配,重新启动服务并且它起作用了。