在Ubuntu 18.04上使用Apache2进行托管ASP.NET Core 2.1应用程序时,如果代理不起作用,可以尝试以下解决方法:
sudo apt-get install libapache2-mod-proxy-html
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo systemctl restart apache2
/etc/apache2/sites-available/000-default.conf
或/etc/apache2/sites-available/default-ssl.conf
文件,并添加以下内容:
ProxyPreserveHost On
ProxyPass / http://localhost:5000/
ProxyPassReverse / http://localhost:5000/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
这样,Apache2会将所有请求代理到ASP.NET Core应用程序运行的默认端口5000。
sudo systemctl reload apache2
现在,Apache2应该能够正确地代理请求到ASP.NET Core应用程序。确保ASP.NET Core应用程序正在监听端口5000(或您指定的端口)。如果仍然存在问题,可以检查Apache2的错误日志/var/log/apache2/error.log
获取更多详细的错误信息。