Ubuntu 上部署 JSP Web 应用的简明步骤
一 准备环境
sudo apt update && sudo apt install openjdk-11-jdkjava -versionsudo apt install tomcat9
sudo systemctl start tomcat9 && sudo systemctl enable tomcat9curl http://localhost:8080wget https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.56/bin/apache-tomcat-9.0.56.tar.gzsudo tar -zxvf apache-tomcat-9.0.56.tar.gz -C /usr/local/usr/local/apache-tomcat-9.0.56/bin/startup.shsudo ufw allow 8080/tcp;后续启用 HTTPS 时放行 443/tcp。二 部署应用
sudo cp your_app.war /var/lib/tomcat9/webapps/http://服务器IP:8080/your_apphttp://服务器IP:8080/manager/htmlhttp://服务器IP:8080/your_app 访问。三 可选 反向代理与 HTTPS
sudo apt install nginx python3-certbot-nginxserver {
listen 80;
server_name your_domain.com www.your_domain.com;
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
sudo ln -s /etc/nginx/sites-available/your_domain /etc/nginx/sites-enabled/ && sudo nginx -t && sudo systemctl restart nginxsudo certbot --nginx -d your_domain.comhttps://your_domain.com(Nginx 终止 TLS,Tomcat 继续在 8080 提供服务)。四 常见问题与排查