首页 > 解决方案 > 为 Tomcat 设置 Apache2

问题描述

如何设置 Apache2 以访问托管在 Tomcat 8 上的 Spring REST API?这个可以吗?它似乎不起作用。

我正在关注本教程https://medium.com/@mirela95/apache-http-server-as-reverse-proxy-with-java-back-end-application-running-on-tomcat-9c8c9210783e

这是我的配置文件。它存储在可用站点下

<VirtualHost *:80>
   ProxyPreserveHost On
   ProxyPass /springrest http://127.0.0.1:8932/
   ProxyPassReverse /springrest http://127.0.0.1:8932/
</VirtualHost>

标签: tomcatapache2reverse-proxy

解决方案


如果那是您的整个配置文件,那么您没有足够的。您必须具有ServerName参数才能使事情正常工作。您需要使用:

<VirtualHost *:80>
    ServerName www.example.com
    ServerAlias example.com

    ProxyPreserveHost on
    ProxyPass /springrest http://localhost:8932/
    ProxyPassReverse /springrest http://127.0.0.1:8932/
    ProxyTimeout 360
</VirtualHost>

该文件通常命名为www.example.com.conf. 一旦你把它放进sites-available去,你就需要运行sudo a2ensite www.example.com然后sudo systemctl restart apache2.


推荐阅读