You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu14.04下Apache2与Tomcat7配置:域名直接访问Java应用方法

How to Map www.mysite.com to Your Tomcat App on Ubuntu 14.04

Hey there! Let's get your setup sorted so users can type www.mysite.com and land directly on your Tomcat-hosted application. Below are two proven methods to achieve this using Apache as a reverse proxy:

Method 1: Reverse Proxy with HTTP (mod_proxy_http)

This is the most straightforward approach, using Apache's proxy modules to forward requests to Tomcat's 8080 port.

  • Step 1: Enable required Apache modules
    Open your terminal and run these commands to enable the proxy and HTTP proxy modules:

    sudo a2enmod proxy proxy_http
    sudo service apache2 restart
    
  • Step 2: Configure Apache Virtual Host
    Edit your default Apache site configuration (or create a new one if you prefer). The file is usually located at /etc/apache2/sites-available/000-default.conf:

    sudo nano /etc/apache2/sites-available/000-default.conf
    

    Inside the <VirtualHost *:80> block, add these lines (replace Application_name with your actual app's context path):

    # Disable proxy requests to avoid open proxy risks
    ProxyRequests Off
    
    # Forward all requests to your Tomcat app
    ProxyPass / http://localhost:8080/Application_name/
    ProxyPassReverse / http://localhost:8080/Application_name/
    

    Save the file (Ctrl+O, then Enter) and exit nano (Ctrl+X).

  • Step 3: Test the setup
    Restart Apache to apply changes:

    sudo service apache2 restart
    

    Now visit www.mysite.com in your browser—it should load your Tomcat application directly!

Method 2: AJP Protocol (mod_proxy_ajp)

AJP is an optimized protocol for communication between Apache and Tomcat, which can offer better performance than plain HTTP. Tomcat enables AJP on port 8009 by default.

  • Step 1: Enable AJP proxy module
    Run these commands to enable the necessary modules:

    sudo a2enmod proxy proxy_ajp
    sudo service apache2 restart
    
  • Step 2: Update Virtual Host configuration
    Open the same virtual host file as before (/etc/apache2/sites-available/000-default.conf) and replace the HTTP proxy lines with these:

    ProxyRequests Off
    
    ProxyPass / ajp://localhost:8009/Application_name/
    ProxyPassReverse / ajp://localhost:8009/Application_name/
    
  • Step 3: Verify Tomcat's AJP connector (optional)
    If you want to double-check Tomcat's AJP setup, open /etc/tomcat7/server.xml and ensure this line is uncommented (it should be by default):

    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
    

    If you made changes here, restart Tomcat:

    sudo service tomcat7 restart
    
  • Step 4: Restart Apache and test

    sudo service apache2 restart
    

    Visit www.mysite.com—you should see your Tomcat app just like with the first method.

Notes to Keep in Mind

  • If your application uses absolute URLs or hardcoded paths, you might need to adjust its configuration to use the root path (/) instead of /Application_name/.
  • Always test configurations after making changes to catch any typos or errors. You can check Apache's syntax with sudo apache2ctl configtest.

内容的提问来源于stack exchange,提问作者SAI GIRI CHARY AOUSULA

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 06:24:46