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

如何通过Amazon Route 53实现无端口访问AWS EC2上的Tomcat应用

解决直接通过xyz.com访问Tomcat部署的ABCProject应用

Hey there! Let's get your app loading directly when someone types xyz.com—no extra port number or project path needed. I've got two reliable approaches for you to pick from, depending on your setup:

方法1:直接修改Tomcat配置(无需额外软件)

This is perfect if you don't want to add extra services and just want to tweak Tomcat's default settings:

  • 修改Tomcat监听端口为80
    Find the conf/server.xml file in your Tomcat installation directory, locate the <Connector> tag that listens on port 8080, and change port="8080" to port="80".

    Heads up: On Linux, binding to port 80 requires root privileges. You can either:

    1. Start Tomcat with sudo (e.g., sudo ./bin/startup.sh)
    2. Use authbind to grant Tomcat permission to bind port 80 without running as root (safer for production)
  • Set ABCProject as Tomcat's default root app
    Choose one of these options:

    1. The easiest way: Rename your ABCProject.war file to ROOT.war, drop it into Tomcat's webapps directory, then restart Tomcat. It'll automatically load as the root application.
    2. More flexible (if you don't want to rename your war): Add a <Context> element inside the <Host> tag in conf/server.xml, like this:
      <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
          <!-- Keep your existing Host config here -->
          <Context path="" docBase="/path/to/your/ABCProject" reloadable="true" />
      </Host>
      
      Replace /path/to/your/ABCProject with the actual path to your project (or your WAR file), then restart Tomcat.

方法2:用Nginx做反向代理(推荐,更灵活)

If you might add SSL, load balancing, or other services later, reverse proxying with Nginx is the better long-term solution:

  • Install Nginx
    Run the right command for your EC2 OS:

    • Ubuntu/Debian: sudo apt update && sudo apt install nginx
    • CentOS/RHEL: sudo yum install nginx
  • Configure reverse proxy rules
    Create a new Nginx config file—like /etc/nginx/sites-available/xyz.com (Ubuntu/Debian) or /etc/nginx/conf.d/xyz.conf (CentOS/RHEL)—and paste this:

    server {
        listen 80;
        server_name xyz.com www.xyz.com;
    
        location / {
            proxy_pass http://localhost:8080/ABCProject/;
            # Pass critical headers to avoid app issues
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }
    
  • Enable the config and restart Nginx

    • Ubuntu/Debian: Create a symlink to enable the config, validate it, then restart:
      sudo ln -s /etc/nginx/sites-available/xyz.com /etc/nginx/sites-enabled/
      sudo nginx -t  # Check for syntax errors
      sudo systemctl restart nginx
      
    • CentOS/RHEL: Validate and restart directly:
      sudo nginx -t
      sudo systemctl restart nginx
      

Critical Checks Don't Forget

  • AWS Security Group: Make sure you add an inbound rule to your EC2 security group allowing HTTP (port 80) from 0.0.0.0/0 (or your desired IP range)—otherwise external users can't reach your app on port 80.
  • SELinux (CentOS/RHEL only): If Nginx can't connect to Tomcat, run sudo setsebool -P httpd_can_network_connect 1 to allow Nginx to make network connections.
  • System Firewall: Ensure your EC2 instance's firewall (ufw, firewalld) allows local access to port 8080 so Nginx can talk to Tomcat.

内容的提问来源于stack exchange,提问作者Sachin Goyal

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.13 07:37:51