安装nginx1.2.0
下载nginx源码包
http://nginx.org/download/nginx-1.2.0.tar.gz
安装pcre支持
yum install pcre-devel
安装nginx
cd /opt/
tar zxvf nginx-1.2.0.tar.gz
cd nginx-1.2.0
./configure --with-http_stub_status_module --prefix=/usr/local/nginx
make && make install
安装完成
cd /usr/local/nginx/sbin/
./nginx
启动 nginx
lsof -i:80
防火墙添加80端口 重启防火墙
访问 http://192.168.1.1
welcome to nginx !
实现简单负载
修改 /usr/local/nginx/conf/nginx.conf
修改内容如下:
http {
include mime.types;
default_type application/octet-stream;
upstream test{
server 192.168.1.2:80 weight=3 max_fails=3 fail_timeout=20s;
server 192.168.1.3:80 weight=3 max_fails=4 fail_timeout=20s;
server 192.168.1.4:80 weight=3 max_fails=1 fail_timeout=20s;
}
server {
listen 80;
server_name www.test.com 192.168.1.1;
index index.html index.htm;
location / {
proxy_pass http://test;
proxy_next_upstream http_500 http_502 http_503 error timeout invalid_header;
include /usr/local/nginx/conf/proxy.conf;
}
}
添加 /usr/local/nginx/conf/proxy.conf
内容如下:
保存退出!
重启nginx。
修改本地hosts文件内容:
192.168.1.1 www.test.com
测试:
访问 http://www.test.com 或 http://192.168.1.1