2015-06-06 54 views
1

這是我的設置:Apache虛擬主機偵聽端口80,重定向到localhost:8080/webapp上的Tomcat。這是我的虛擬主機設置:從Apache轉向Tomcat打破Grails休息API調用

<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域類的設置作爲一種資源,像這樣:

@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']] 
... } 

所以我的問題是,如何使REST調用這個控制器的時候被Apache轉發到/ web應用程序,將工作?我想我可能需要的是一種告訴Grails將APIController映射到某處的方法。我也嘗試了UrlMappings.groovy,但沒有運氣。

更新:

我添加的serverURL和應用程序上下文Config.grooy,沒有運氣:

grails.serverURL = "http://example.com" 
grails.app.context="/webapp" 

另外,我用AJP協議與Apache而非http轉發,更新虛擬主機配置:

ProxyRequests Off 
ProxyPass /webapp ajp://localhost:8009/webapp 
ProxyPassReverse /webapp ajp://localhost:8009/webapp 
RedirectMatch (.*) ajp:/xxx/webapp 

回答

0

原來,這不是一個Apache/Tomcat的問題......但與Grails的東西。我不是特別解決這個問題的東西,但它與其他控制器有關。我重新創建了特定的其餘控制器,並且工作。

0

如果應用程序是根據兩個上下文運行,所以/webapp/api網絡那麼你需要你的VirtualHost還包含:

ProxyPass /api http://localhost:8080/api 
ProxyPassReverse /api http://localhost:8080/api 

如果您的REST API是/webapp/api下運行,那麼我建議打它在Chrome或Firefox和看到的網絡選項卡顯示在開發工具的要求。

+0

api不在不同的環境下運行,它是/ webapp應用程序的一部分。如果在localhost:8080/webapp/api上運行。我可以瀏覽到/ api就好了,但當推送到服務器,並與虛擬主機有Apache轉發,我無法通過瀏覽器到達鏈接,我找不到404。 –