码迷,mamicode.com
首页 > Web开发 > 详细

Nginx+Keepalived+Tomcat之动静分离的web集群

时间:2014-12-10 16:05:03      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:http   io   ar   os   sp   for   on   cti   ad   

#vi /etc/nginx/nginx.conf
############################################
user nginx nginx;
worker_processes 4;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
upstream tomcat_server {
# ip_hash;
server 192.168.1.17 weight=2;
server 192.168.1.20 max_fails=2 fail_timeout=30s;
}
upstream apache_server {
ip_hash;
server 192.168.1.19;
}
upstream nginx_server {
ip_hash;
server 192.168.1.18;
}
server
{
listen 80;
server_name www.abc.com;
location / {
index index.html index.php index.htm index.jsp index.do default.do;
root html;
if (-d $request_filename)
###############################################
{
rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
}
location ~ \.(jsp|jspx|do)?$ {
proxy_set_header Host %host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://tomcat_server;
}
###############################################
location ~ \.(php|php5)?$ {
proxy_set_header Host %host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://nginx_server;
}
#############################################
location ~ \.(html|htm)?$ {
proxy_set_header Host %host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://apache_server;
}
#############################################
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
expires 30d;
}
location ~ .*\.(js|css)?$ {
expires 1h;
}
#############################################
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}

Nginx+Keepalived+Tomcat之动静分离的web集群

标签:http   io   ar   os   sp   for   on   cti   ad   

原文地址:http://www.cnblogs.com/steven9801/p/4155306.html

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