首页 > 解决方案 > Apache 无法使用 ProxyPass 托管 ASP.NET Core 应用程序

问题描述

我希望我的 ASP.NET Core 应用程序通过 Apache 托管,以便端口80重定向到 port50005001https。(我的本地 IP 是 192.168.1.250 用于结果中的上下文)

我尝试了以下配置,结果各不相同:

<VirtualHost *:80>
    ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:5000/
    ProxyPassReverse / http://127.0.0.1:5000/
    ErrorLog /var/log/apache2/myapp.log
    CustomLog /var/log/apache2/myapp.log common
</VirtualHost>

会将我重定向到端口 5001,但我在 Chrome 中得到了这个:

This site can’t be reached: 192.168.1.250 refused to connect.
Try:

Checking the connection
Checking the proxy and the firewall
ERR_CONNECTION_REFUSED

<VirtualHost *:80>
    ProxyPreserveHost On
    ProxyPass / https://127.0.0.1:5001/
    ProxyPassReverse / https://127.0.0.1:5001/
    ErrorLog /var/log/apache2/myapp.log
    CustomLog /var/log/apache2/myapp.log common
</VirtualHost>

这个配置给了我一个500 Internal Server Error

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at [no address given] to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

Apache/2.4.25 (Debian) Server at 192.168.1.250 Port 80

<VirtualHost *:80>
    ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:5001/
    ProxyPassReverse / http://127.0.0.1:5001/
    ErrorLog /var/log/apache2/myapp.log
    CustomLog /var/log/apache2/myapp.log common
</VirtualHost>

这个配置给了我一个502 Proxy Error

Proxy Error
The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request

Reason: Error reading from remote server

Apache/2.4.25 (Debian) Server at 192.168.1.250 Port 80

关于可行的配置的任何想法?

标签: apacheasp.net-coreproxyconfigurationdebian

解决方案


不知道你是否解决了这个问题,但我在 Ubuntu/Apache 上的 dotNet Core 5.0 也有类似的问题。

阅读这篇文章后,我解决了它(有点):. NET Core 3.1 API - 307 Temporary Redirect

基本上删除app.UseHttpsRedirection(); 应用程序中的行,因此它现在仅在 http://localhost:5000/ 上运行

现在 Apache 并没有尝试代理您的 SSL 站点,而是您在端口 5000 上的标准站点。因为它位于 127.0.0.1(我相信)上,所以应该足够安全(但很高兴对此进行纠正......)

分享


推荐阅读