您的位置:首页 > 运维架构 > Tomcat

Nginx+Tomcat配置转发到不同域名下的不同项目

2015-12-31 18:16 681 查看
摘要: Nginx+Tomcat配置转发项目访问地址如http://www.xxoo.com:port/project/

本人新手,胡乱搞的,喷可以,但是轻一点,我怕痛。

应届毕业生上班第二周,此为背景,华丽的分割线。

-----------------------------------------------------------------

公司服务器上,跑着3个项目,tomcat1上跑一个,tomcat2上跑着两个,而且访问地址都是:
http://www.xxoo.com:port/project/
域名:端口/项目名

由于是一台服务器,而且是不同tomcat,tomcat下又有不同项目,老板说的是需要直接根据域名就可以访问。本人玩过Apache服务器,配置起来不是很顺畅,所以就使用了nginx做端口转发,tomcat做项目区分,具体配置如下(nginx参照osc的):

server{
listen 80;
server_name localhost;
location / {
deny all;
}

location ~ ^ /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
}

server {
listen 80;
server_name www.xxoo1.com;
location / {
proxy_pass xxxx.xxxx.xxxx.xxxx:8081;
include proxy.conf;
}

location ~ ^/WEB-INF {
deny all;
}

}

server {
listen 80;
server_name www.xxoo2.com;
location / {
proxy_pass xxxx.xxxx.xxxx.xxxx:8080;
include proxy.conf;
}

location ~ ^/WEB-INF {
deny all;
}

}

貌似nginx只可以转发端口,不能做到根据项目名称转发,摆渡了几次,没搞定,所以,就对tomcat下手了。

具体配置如下:
<Host name="localhost"  appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="/" docBase="" reloadable="true"/>
</Host>
<Host name="www.xxoo1.com"  appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="/project1" docBase="project1" reloadable="true"/>
</Host>
<Host name="www.xxoo2.com"  appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="/project2" docBase="project2" reloadable="true"/>
</Host>
额,大概就是这么个意思...
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: