1.下载,解压
因为配置两个tomcat,所以需要两个tomcat
2修改其中一个tomcat的端口号
我的例子一个是8080,另一个是8088
3配置nginx-1.4.5\conf\nginx.conf
upstream backend {
server localhost:8088;
server localhost:8080;
ip_hash;
}
location / {
root html;
index index.html index.htm;
proxy_pass http://backend;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|ico|swf|js|css)$ {
root c:/server;
expires 1d;
}
listen 800;//默认是80,我修改成了800,看个人需要
4.随便写个网页
我的是在tomcat下 webapp下 新建 ng_test / index.html
两个tomcat下的工程要同步
index.html 代码如下(ps:图片放在c:/server/image/sfl.jpg)
配置静态文件处理(图片等)
<BODY>
<P>
<H3>shifulong nginx test</H3>
<H3>Apache Tomcat Examples</H3>
<P></P>
<ul>
<li><a href="http://www.baidu.com">baidu</a></li>
<li><a href="http://www.renren.com">renren</a></li>
<img src="http://localhost:800/image/sfl.jpg" width="400" height="600"/>
</ul>
</BODY></HTML>
5启动服务
先启两个tomcat,然后cmd 到nginx目录下 执行 nginx.exe
ps:停止nginx服务 neinx -s stop
6访问(注意端口号)
浏览器访问 http://localhost:800/ng_test/index.html
通过三个端口号访问的结果是一样的(800是nginx端口,8080和8088是tomcat端口)