【问题标题】:Apache can't host ASP.NET Core app using ProxyPassApache 无法使用 ProxyPass 托管 ASP.NET Core 应用程序
【发布时间】:2020-11-22 07:22:32
【问题描述】:

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

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

  • 代理到http://127.0.0.1:5000/
<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

  • 代理到https://127.0.0.1:5001/
<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

  • 代理到http://127.0.0.1:5001/
<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

关于可行的配置有什么想法吗?

【问题讨论】:

    标签: apache asp.net-core proxy configuration debian


    【解决方案1】:

    不知道你是否解决了这个问题,但我在 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(我相信)上,因此应该足够安全(但很高兴能够对此进行纠正......)

    分享

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-04
      • 1970-01-01
      • 2019-11-20
      • 2019-08-15
      相关资源
      最近更新 更多