Ubuntu服务器在nginx的基础上增加一个Tomcat,要怎么实现?
我本身服务器是用了LNMP的,就是Nginx了,挂了一个PHP网站,现在想挂一个JSP网站上去,现在要在服务器上安装Tomcat,并绑定一个域名上去。Tomcat的默认端...
我本身服务器是用了LNMP的,就是Nginx了,挂了一个PHP网站,现在想挂一个JSP网站上去,现在要在服务器上安装Tomcat,并绑定一个域名上去。Tomcat的默认端口号是8080,要怎么做?
Nginx上的网站也绑定了一个域名的 展开
Nginx上的网站也绑定了一个域名的 展开
1个回答
2016-06-11 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
1. Tomcat Configuration
Edit server.xml, check the Tomcat listening port, and configure the default path to /apple
/etc/tomcat7/server.xml
<!-- Tomcat listen on 8080 -->
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
URIEncoding="UTF-8"
redirectPort="8443" />
<!-- Set /apple as default path -->
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context path="" docBase="apple">
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>
</Host>
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.
Edit server.xml, check the Tomcat listening port, and configure the default path to /apple
/etc/tomcat7/server.xml
<!-- Tomcat listen on 8080 -->
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
URIEncoding="UTF-8"
redirectPort="8443" />
<!-- Set /apple as default path -->
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context path="" docBase="apple">
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>
</Host>
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.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询