下载nginx源安装包
http://nginx.org/en/linux_packages.html
找到对应Linux版本的连接,这里选CentOS 6,右击复制链接地址”http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
”
在linux下下载nginx源的rpm包并安装
wget http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
rpm -ivh nginx-release-centos-6-0.el6.ngx.noarch.rpm
通过nginx源安装nginx最新版
yum -y install nginx
安装成功,启动nginx
用浏览器访问nginx服务器的80端口,显示下图说明Nginx已经正常启动
从Tomcat官网(http://tomcat.apache.org/)下载Tomcat8
wget http://apache.fayea.com/tomcat/tomcat-8/v8.0.23/bin/apache-tomcat-8.0.23.tar.gz
解压缩tomcat包
tar xzf apache-tomcat-8.0.23.tar.gz
把tomcat改名复制两份,分别叫tomcat1,tomcat2
mv apache-tomcat-8.0.23 tomcat1
cp -ar tomcat1 tomcat2
这里是把两个Tomcat Web服务配在了同一台服务器上,所以下边这些端口要修改,两个Tomcat的端口配置不能重复。
进入tomcat2/conf,编辑server.xml
把默认的8005改成8006
把默认的8080改成8081
把默认的8009改成8010
tomcat1 | tomcat2 | |
shutdown | 8005 | 8006 |
http | 8080 | 8081 |
ajp | 8009 | 8010 |
在tomcat1/webapps/ROOT下创建test.jsp,内容如下
<html>
<body>
<h1>TOMCAT_1 JSP Test Page</h1>
<%=new java.util.Date()%>
</body>
</html>
在tomcat2/webapps/ROOT下创建test.jsp,内容如下
<html>
<body>
<h1>TOMCAT_2 JSP Test Page</h1>
<%=new java.util.Date()%>
</body>
</html>
启动tomcat1和tomcat2
tomcat1/bin, 运行./startup.sh
tomcat2/bin, 运行./startup.sh
访问服务器的:8080/test.jsp,打开测试页
访问服务器的:8081/test.jsp,打开测试页
完整的nginx.conf配置,蓝色代表修改或新增内容
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
use epoll;
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘
‘$status $body_bytes_sent "$http_referer" ‘
‘"$http_user_agent" "$http_x_forwarded_for"‘;
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
upstream login_server{
server 115.159.76.128:8080;
server 115.159.76.128:8081;
}
server{
listen 80;
server_name mxyx.login;
index index.jsp;
root /home/www;
location /
{
proxy_set_header HOST $host;
proxy_pass http://login_server;
proxy_set_header X-Real-IP $remote_addr;
}
}
#include /etc/nginx/conf.d/*.conf;
}
修改好后,重启Nginx即可。
原文地址:http://zl1030.blog.51cto.com/274507/1657086