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

求助:Spring Boot应用启动失败,Tomcat 80端口无法启动

解决Spring Boot在Linux下Tomcat 80端口启动失败的问题

Hey there, let's work through this Tomcat port issue you're hitting with your Spring Boot app on Linux. This is a super common snag, so I'll walk you through the most likely fixes step by step.

第一步:确认80端口是否真的被占用

First up, let's verify if another process is actually using port 80. Run one of these commands in your terminal:

  • Use ss (a modern replacement for netstat):
    ss -tulpn | grep :80
    
    This will show you the PID and name of the process hogging port 80 (if any). The -p flag links the port directly to the running process, which is exactly what we need here.
  • Or use lsof (install it first if you haven't: sudo apt install lsof for Debian/Ubuntu, sudo yum install lsof for RHEL/CentOS):
    lsof -i :80
    

第二步:处理端口占用的情况

If you find a process using port 80, you have two straightforward options:

  • Kill the conflicting process (only do this if you're sure it's not a critical service):
    kill -9 <PID>
    
    Replace <PID> with the process ID you found in the previous step.
  • Change your Spring Boot app's port:
    This is often the safer choice if you don't want to disrupt existing services. You can do this in a few ways:
    1. Edit your application.properties file:
      server.port=8080  # Or any other unused port like 8081
      
    2. If you use YAML, edit application.yml:
      server:
        port: 8080
      
    3. Specify the port directly when launching the app:
      java -jar your-spring-boot-app.jar --server.port=8080
      

第三步:检查端口权限(容易被忽略!)

On Linux, non-root users can't bind to ports below 1024 (including 80) by default. If you're running your Spring Boot app as a regular user, this could be the root cause. Here are your fixes:

  • Option 1 (Not recommended for production): Run the app as root. This works but poses security risks, so avoid it if possible.
  • Option 2: Grant the Java executable permission to bind low ports using setcap:
    sudo setcap 'cap_net_bind_service=+ep' /path/to/your/java
    
    Replace /path/to/your/java with the actual path to your Java binary (e.g., /usr/bin/java). After running this, your regular user can launch the app on port 80 without issues.
  • Option 3 (Best for production): Use Nginx as a reverse proxy. Let Nginx listen on port 80, then forward requests to your Spring Boot app running on a higher port (like 8080). This is the standard production approach—it adds security, load-balancing capabilities, and more flexibility.

最后验证

Once you've tried one of the fixes, restart your Spring Boot app and check if it launches successfully. If you still run into issues, double-check that the port you're using isn't blocked by a firewall (run sudo ufw allow 80 or adjust your firewall rules accordingly if needed).

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 07:49:36