2014-02-26 66 views
0

我在Apache後面運行tomcat。我還擁有Spring安全性來處理授權和身份驗證以及Struts 2作爲我的Web層框架。通過tomcat顯示主頁而不更改url

這是我的要求: 1)我想有一個主頁,顯示一些數據是動態的(如類別),它必須從數據庫中獲取並動態呈現。 2)我想在地址欄中點擊「mysite.com」而不更改URL即顯示上面的頁面。瀏覽器地址欄中必須顯示「僅mysite.com。

我可以很容易保持本網頁上我的虛擬主機的DocumentRoot位置的index.html。然而,由於是動態生成的一些內容我不能做到這一點。

另一種選擇是保持這種對Tomcat和要求阿帕奇轉發到tomcat。但是這改變了我的地址欄上的URL請求。

我該如何處理?能否在JK_MOD ForwardDirectories選項一起使用?

回答

0

現在可以說我有一個webapp「mysite」,它運行在apache後面的tomcat上。這個mysite webapp有一個域名「mysite.com」。 當我點擊「mysite.com」時,它必須返回包含動態內容的主頁。所以我把它作爲index.jsp添加到webapps/mysite /目錄中。

Follwing是虛擬主機我寫了mysite的應用:

 <VirtualHost *:86> 
      ServerAdmin [email protected] 
      DocumentRoot "D:/var/www/html/mysite" 
      ServerName mysite.com 
      ServerAlias www.mysite.com 
      ErrorLog "logs/mysite-error.log" 
      CustomLog "logs/mysite-access.log" common 

     <Directory "D:/var/www/html/mysite"> 
        # 
        # Possible values for the Options directive are "None", "All", 
        # or any combination of: 
        # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI            
        #MultiViews 
        # Note that "MultiViews" must be named *explicitly* --- "Options All" 
        # doesn't give it to you. 
        # 
        # The Options directive is both complicated and important. Please see 
        # http://httpd.apache.org/docs/2.4/mod/core.html#options 
        # for more information. 
        # 
        Options -Indexes +FollowSymLinks 

        # 
        # AllowOverride controls what directives may be placed in .htaccess files. 
        # It can be "All", "None", or any combination of the keywords: 
        # Options FileInfo AuthConfig Limit 
        # 
        AllowOverride None 

        # 
        # Controls who can get stuff from this server. 
        # 
       Require all denied 
      Require local granted 
      </Directory> 
     JkMount /mysite/* localtomcat 
     ProxyRequests Off 
     ProxyPreserveHost On 

     ProxyPass /mysite/ ! 
     ProxyPass/http://localhost:8080/mysite/ 
     ProxyPassReverse/http://localhost:8080/mysite/ 

      </VirtualHost> 

所以,這裏是我的問題上面的實現: 1)我做的是混合了mod_jk和mod_proxy的的的ProxyPass的JKMount。即使 這工作如何標準它是 2)它有任何嚴重的副作用? 3)什麼可能是替代解決方案?

+0

您接受的答案是一個問題? :( –

+0

是的,對不起,這是因爲我已經成功地實現了這個東西,它在生產中運行良好,但是我想知道它是否是好方法,以及它是否存在任何缺陷。你將使它成爲一個完整的答案,而不是一個半熟的問題和答案。 –

+0

你的配置看起來很好,但我不知道爲什麼你會打擾使用不同的協議來連接到不同的Tomcat後端。 –

0

要將動態內容從Tomcat提供給特定域,請執行以下操作:

  1. 在處理「mysite.com」的apache web服務器上創建虛擬主機。
  2. 通過mod_jk的地圖你的虛擬主機到Tomcat的全部內容:

    JkMount/ tomcatsJVMRouteName 
    JkMount /*  tomcatsJVMRouteName 
    
  3. 創建雄貓server.xml中的另一臺主機來處理「mysite.com」。

  4. 將您的應用程序部署爲默認應用程序(webapps/ROOT-directory)。
+0

將應用程序部署爲默認應用程序(webapps/ROOT-directory)是一個好主意嗎?我聽說tomcat傢伙不鼓勵它。有沒有其他方法可以做到這一點 –

+0

此外,這不會工作,因爲我有多個應用程序在我的tomcat中運行,具有與我的問題 –

+1

中所述的相同要求。您可以爲不同應用程序創建不同的主機,以運行於不同的webapp目錄。 – Stefan