# Tomcat+Nginx集群
## Tomcat
* 修改/etc/profile中的环境变量
```
export JAVA_HOME=/usr/java/jdk1.7.0_80
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME$/lib/tools.jar
export MAVEN_HOME=/home/developer/apache-maven-3.0.5
export PATH=$PATH:$JAVA_HOME/bin:$CLASSPATH:$MAVEN_HOME/bin
export CATALINA_BASE1=/home/developer/apache-tomcat-7.0.73-1
export CATALINA_HOME1=/home/developer/apache-tomcat-7.0.73-1
export CATALINA_TMPDIR1=/home/developer/apache-tomcat-7.0.73-1
export TOMCAT_HOME1=/home/developer/apache-tomcat-7.0.73-1
export CATALINA_BASE2=/home/developer/apache-tomcat-7.0.73-2
export CATALINA_HOME2=/home/developer/apache-tomcat-7.0.73-2
export CATALINA_TMPDIR2=/home/developer/apache-tomcat-7.0.73-2
export TOMCAT_HOME2=/home/developer/apache-tomcat-7.0.73-2
```
* 增加第二个tomcat的catalina.sh配置
```
# OS specific support. $var _must_ be set to either true or false.
export CATALINA_BASE=$CATALINA_BASE2
export CATALINA_HOME=$CATALINA_HOME2
```
## nginx
* 修改conf/nginx.conf
```
include vhost/*.conf;
```
* vhost目录下增加文件www.x.com.conf
* www.x.com.conf中的内容
```
server {
default_type ‘text/html‘;
charset utf-8;
listen 80;
autoindex on;
server_name www.x.com;
access_log /usr/local/nginx/logs/access.log combined;
index index.html index.htm index.jsp index.php;
location / {
proxy_pass http://127.0.0.1:8080;
}
}
```
## 负载均衡
weight表示访问权重,默认权重为1
## 修改www.x.com.conf中的内容
```
upstream www.x.com{
server 127.0.0.1:8080 weight=1;
server 127.0.0.1:9080 weight=9;
}
server {
default_type ‘text/html‘;
charset utf-8;
listen 80;
autoindex on;
server_name www.x.com;
access_log /usr/local/nginx/logs/access.log combined;
index index.html index.htm index.jsp index.php;
location / {
proxy_pass http://www.x.com;
}
}
```