Nginx是一个web服务器也可以用来做负载均衡及反向代理使用,目前使用最多的就是负载均衡,详细见百度
下载地址:http://nginx.org/en/download.html,我选择的版本是nginx-1.10.3(如果版本不一致可能存在差异)。
下载下来压缩包为nginx-1.10.3.tar.gz。请使用tar -xzvf nginx-1.10.3.tar.gz解压
默认安装目录为:/usr/local/nginx
为了使得配置的server更加清晰,此处将每一个server单独剥离出来,场景如下:
有两台应用服务器,IP+PORT分别为:10.100.96.142:8080和10.100.96.143:8080,需配置轮询负载均衡
在/usr/local/nginx/conf下创建vhost目录,新建8080.xml(名字随意)文件8080.xml配置如下:
server { listen 80; server_name 8080; #access_log logs/host.access.log main; location /ssm { root html; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 location ~ .*$ { proxy_pass http://8080; } }配置/usr/local/nginx目录下的nginx.xml(注意upstream的配置,有需要可以加权重weight):
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; upstream 8080 { server 10.100.96.142:8080; server 10.100.96.143:8080; } include vhost/*.conf; }