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

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

你可能感兴趣的:(keepalived)