apache - Apache 无法使用 ProxyPass 托管 ASP.NET Core 应用程序
问题描述
我希望我的 ASP.NET Core 应用程序通过 Apache 托管,以便端口80
重定向到 port5000
或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
关于可行的配置的任何想法?
解决方案
不知道你是否解决了这个问题,但我在 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(我相信)上,所以应该足够安全(但很高兴对此进行纠正......)
分享
推荐阅读
- javascript - 未捕获的类型错误:无法读取未定义的属性“发送”
- spring - 无法更改 Manifest.mf 中的 Main-Class 属性
- python - Python中的Memset(),清除缓冲区
- java - 防止Java 8的map()reduce()中的空指针用于BigDecimal加法
- cuda-gdb - cuda-gdb 附加:一个程序已经在调试中。杀了它?
- javascript - 使用 vue js 在 ipad(触摸设备)上禁用悬停效果和双击问题
- python - kmeans集群新手
- android-studio - 如何捏缩放 Android 模拟器嵌入在 Android Studio IDE (2020)
- c# - C#如何生成一个范围内的随机数,偏向范围的低端?
- python - 如何在不等待的情况下向 Celery 发送任务?