Ubuntu服务器在nginx的基础上增加一个Tomcat,要怎么实现?

2025-04-06 19:43:06
推荐回答(1个)
回答1:

1. Tomcat Configuration
Edit server.xml, check the Tomcat listening port, and configure the default path to /apple
/etc/tomcat7/server.xml


connectionTimeout="20000"
URIEncoding="UTF-8"
redirectPort="8443" />


unpackWARs="true" autoDeploy="true">



WEB-INF/web.xml




Restart Tomcat, make sure when you access 127.0.0.1:8080, it will display the content in 127.0.0.1:8080/apple

2. Nginx Configuration
In Nginx, edit /etc/nginx/sites-enabled/default, put following content :
/etc/nginx/sites-enabled/default

server {
listen 80;
server_name yourdomain.com;
root /etc/tomcat7/webapps/apple;

proxy_cache one;

location / {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8080/;
}
}

It tells Nginx to redirect the traffics from port 80 to Apache Tomcat on port 8080. Done, restart Nginx.