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

如何在不支持Tomcat的Plesk Onyx 17.8中部署.war文件并运行Java代码?

Running Java Code on Plesk-Managed Servers (Post 17.8)

Since Plesk dropped bundled Tomcat starting from version 17.8, and downgrading to older versions is risky due to security vulnerabilities and approaching end-of-life, here are three robust, secure alternatives to get your Java apps up and running:

1. Manual Tomcat Installation (Best for WAR Deployments)

This is the most straightforward approach if you need to deploy traditional .war files:

  • Install Tomcat via package manager: Connect to your server via SSH or Plesk's built-in Terminal, then run the appropriate command for your OS:
    • Debian/Ubuntu: apt update && apt install tomcat9 (adjust version number if needed, e.g., tomcat10)
    • CentOS/RHEL: dnf update && dnf install tomcat
  • Start and enable Tomcat: Ensure the service runs on boot with:
    systemctl start tomcat
    systemctl enable tomcat
    
  • Deploy your WAR file: Upload your .war to Tomcat's webapps directory (typically /var/lib/tomcat9/webapps/). Tomcat will automatically unpack and deploy the app within a minute.
  • Configure Plesk reverse proxy: For your target domain in Plesk, go to Apache & Nginx Settings, then add these lines to Additional Apache directives to route traffic to Tomcat:
    # Replace /your-app with / if you want the root domain to point to your Java app
    ProxyPass /your-app http://localhost:8080/your-app
    ProxyPassReverse /your-app http://localhost:8080/your-app
    
    Save the settings, and your app will be accessible at https://your-domain.com/your-app.

2. Dockerized Java Apps (Flexible, Isolated Environments)

Docker is perfect if you need to run multiple Java versions, isolate apps, or use custom configurations:

  • Install the Docker extension in Plesk: Go to Extensions, search for "Docker", and install the official extension.
  • Create a Tomcat container: Use the official Tomcat image (e.g., tomcat:9-jdk11 for Java 11 + Tomcat 9) and mount a local directory (like your domain's httpdocs) to persist WAR files. Alternatively, build a custom Docker image with your pre-deployed app.
  • Map ports and set up reverse proxy: Map the container's 8080 port to a server port, then configure Plesk's reverse proxy (same as step 1) to route domain traffic to this port.
  • Bonus: Docker makes it easy to update or roll back your Java environment without affecting other server components.

3. Run Standalone Java JARs (e.g., Spring Boot)

If your app is packaged as an executable JAR (common with Spring Boot, Quarkus, etc.):

  • Test the JAR first: Run it via Terminal to confirm it works:
    java -jar /var/www/vhosts/your-domain.com/httpdocs/your-app.jar
    
  • Set up a systemd service: To keep the app running in the background and auto-start on server reboot, create a service file at /etc/systemd/system/your-app.service:
    [Unit]
    Description=My Spring Boot Application
    After=network.target
    
    [Service]
    User=your-plesk-username # Replace with your actual Plesk user
    WorkingDirectory=/var/www/vhosts/your-domain.com/httpdocs
    ExecStart=/usr/bin/java -jar your-app.jar
    Restart=always # Auto-restart if the app crashes
    
    [Install]
    WantedBy=multi-user.target
    
  • Enable and start the service:
    systemctl daemon-reload
    systemctl start your-app
    systemctl enable your-app
    
  • Configure reverse proxy: Just like with Tomcat, add proxy rules in Plesk to forward traffic to your JAR's listening port (default 8080 for Spring Boot).

Key Notes

  • Firewall rules: Make sure Tomcat/JAR ports (8080, or custom ports you use) are allowed in both your server's firewall and Plesk's Firewall module.
  • Permissions: Ensure the Tomcat user or your Plesk user has read/write access to your app files to avoid deployment errors.
  • Logs: Check Tomcat logs at /var/log/tomcat9/ or view your standalone app logs with journalctl -u your-app.service for troubleshooting.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.12 05:22:10