以下是我的设置:Apache虚拟主机侦听端口80,重定向到localhost:8080 / webapp上的Tomcat。这是我的虚拟主机设置:
<VirtualHost xxx>
ServerAdmin xxx
DocumentRoot "xxx"
ServerName xxx
ProxyRequests Off
ProxyPass /webapp http://localhost:8080/webapp
ProxyPassReverse /webapp http://localhost:8080/webapp
RedirectMatch (.*) xxx/webapp
<Location "/">
# Configurations specific to this location. Add what you need.
# For instance, you can add mod_proxy_html directives to fix
# links in the HTML code. See link at end of this page about using
# mod_proxy_html.
# Allow access to this proxied URL location for everyone.
Order allow,deny
Allow from all
</Location>
我将Grails Domain Class设置为如下资源:
@Resource(uri='/agegroup',formats=['json'],readOnly=true)
class AgeGroup { ...}
这按预期工作,我可以浏览http://www.example.com/webapp/agegroup一切正常。这是问题...我有一个宁静的控制器,我想在/ api调用。这可以在Tomcat中运行localhost:8080 / webapp并调用/ api,但不能在Apache转发中运行。这是控制器:
import static org.springframework.http.HttpStatus.*
import static org.springframework.http.HttpMethod.*
import groovy.json.*
class ApiController extends RestfulController{
static responseFormats = [index: ['json']]
... }
所以我的问题是,如何对这个控制器进行休息调用,当Apache转发到/ webapp时它会工作?我想我可能需要的是告诉Grails在某处映射ApiController的方法。我也试过UrlMappings.groovy,但没有运气。
更新
我已将serverURL和app上下文添加到Config.grooy,没有运气:
grails.serverURL = "http://example.com"
grails.app.context="/webapp"
另外,我使用AJP协议转发Apache而不是http,更新了vhost config:
ProxyRequests Off
ProxyPass /webapp ajp://localhost:8009/webapp
ProxyPassReverse /webapp ajp://localhost:8009/webapp
RedirectMatch (.*) ajp:/xxx/webapp
答案 0 :(得分:0)
如果Web应用程序在两个上下文中运行/webapp
和/api
,那么您需要VirtualHost
还包含:
ProxyPass /api http://localhost:8080/api
ProxyPassReverse /api http://localhost:8080/api
如果您的Rest API在/webapp/api
下运行,那么我建议您在Chrome或Firefox中点击它,然后在开发者工具中查看网络标签显示的请求。
答案 1 :(得分:0)
原来这不是Apache / Tomcat的问题......而是Grails的东西。我不是特别修复了这个问题,但它与其他控制器有关。我重新创建了那个特定的休息控制器,它起作用了。