码迷,mamicode.com
首页 > 其他好文 > 详细

Tomcat+Nginx集群

时间:2018-04-03 14:26:19      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:ext   /etc   $path   log   efault   char   均衡   dir   var   

# 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;
}
}
```

Tomcat+Nginx集群

标签:ext   /etc   $path   log   efault   char   均衡   dir   var   

原文地址:https://www.cnblogs.com/dayaodao/p/8707642.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!