环境:centos6.5
一、编辑安装nginx
http://nginx.org/en/download.html
使用Stable version 稳定版本
./configure –prefix=/usr/local/nginx
vim nginx.conf
主要修改这几个地方
user daichen; 让子进程都是自定义用户 不能root
worker_processes 4; 工作进程 一般和cpu核心数一致
pid logs/nginx.pid;
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
#root /home/daichen/web;
//apache地址
proxy_pass http://127.0.0.1:8081;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
index index.html index.htm;
}
二、编译安装apache
http://blog.csdn.net/web_orange/article/details/74011343
最终达到的效果就是 访问 nginx服务器 会自动转向到apache webserver
三、克隆一台机器 作为负载均衡子机
在server {} 前配置 upstream [有很多参数 比如权重weight backup备用机等 可以百度]
配置 proxy_pass http://daichen; daichen 为upstream后面的自定义名字
upstream daichen
{
server 172.16.180.132:80 weight=1;
server 172.16.180.131:8081 weight=5;
}
server {
listen 80;]
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
#root /home/daichen/web;
#proxy_pass http://127.0.0.1:8081;
proxy_pass http://daichen;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header MYNAME daichen;
index index.html index.htm;
}
基本的负载均衡就配置好了