nginx实现负载均衡

其实配置非常简单nginx.conf: 

#user  nobody;
worker_processes  1;

error_log  logs/error.log;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;

    #gzip  on;
    upstream  sphl520.taobao.com   {
              server   192.168.1.121:8080;
              server   192.168.1.122:8080;
    }
    server {
        listen       80;
        server_name  sphl520.taobao.com;
        charset utf-8;
        location / {
            root   html;
            index  index.html index.htm;
            proxy_pass        http://sphl520.taobao.com;
            proxy_set_header  X-Real-IP  $remote_addr;
            client_max_body_size  100m;
        }


        location ~ ^/(WEB-INF)/ { 
	    deny all; 
        } 

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    }
}


将 http://sphl520.taobao.com 替换成你的域名 
192.168.1.121:8080 和 192.168.1.122:8080 替换成你服务器的IP 

OK,已经完成。启动nginx即可。 

你可能感兴趣的:(tomcat,nginx,负载均衡)