nginx+tomcat 配置多域名集群
1、将nginx安装好
2、将tomcat安装好
3、将开发好的网站发布到tomcat的webapp文件夹下
4、在tomcat的conf/server.xml按照如下配置<Host name="www.x旌忭檀挢xxx.com" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Context path="" docBase="/root/apache-tomcat-8.0.24/webapps/xxxx" reloadable="true" > </Context> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> </Host>其中 host标签 name属性配置你要的域名docBase里最好配置你访问的网站项目的绝对地址完成上述配置,tomcat已经配置完成
5、在nginx当中如下配置配置nginx下 conf/nginx.conf文件配置内间恒溪痞容如下:upstream site { ip_hash; server 192.168.1.6:8080; server 192.168.1.7:8080; }在http标签下配置集群,当中ip_hash是根据ip地址的hash算法来处理,意思就是1个ip会固定对应一台服务器。server{listen 80; server_name www.xxxx.com; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.jsp; proxy_pass http://site; proxy_set_header Host $host; }}在server当中配置以上内容listen 80 监听80端口server_name 监听的域名location 系列配置需要注意的是proxy_pass http://你配置的集群的名字在本例子中是upstream site 中的siteproxy_set_header Host $host;//该语句将头文件中的域名信息传递给集群,这个语句是保证能过通过代理跳转多域名的关键