参考:
Centos下安装、Nginx笔记(一) 简单安装
Centos下安装、Nginx笔记(三) 代理服务器keepalived的安装及配置实现代理集群功能
说明:
1、环境准备
Nginx反向代理服务器:
系统 Centos 5.4 + ngix
外网IP: 60.x.x.13
内网IP: 192.168.10.13
web1服务器:
系统: windows 2003 IIS
内网 ip: 192.168.10.2
web2服务器:
系统windows 2003+IIS
内网 ip 192.168.10.3 (2/3的页面内容设置不一样以便最后测试的时候进行查看)
2、Nginx反向代理服务器 做负载均衡配置:
此次配置实现内容:
1)访问代理服务器 访问的是Nginx代理服务器本身的网站;
2)访问代理服务器:8800时实现跳转到内网2台web服务器进行负载;
具体见配置说明。
#vi /usr/local/nginx/conf/nginx.config
-------------------------------
nginx.config -----------------------------------
-
#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 {
-
use epoll;
-
worker_connections 1024;
-
}
-
-
-
http {
-
include mime.types;
-
default_type application/octet-stream;
-
-
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
-
'$status $body_bytes_sent "$http_referer" '
-
'"$http_user_agent" "$http_x_forwarded_for"';
-
-
access_log logs/access.log main;
-
-
sendfile on;
-
#tcp_nopush on;
-
-
#keepalive_timeout 0;
-
keepalive_timeout 65;
-
tcp_nodelay on;
-
-
#gzip on;
-
gzip on;
-
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
-
-
#========= server 80 ====== 如果访问centos 80端口是访问到nginx代理服务器自身的站点
-
server {
-
listen 80;
-
#有域名可用域名
-
server_name 60.x.x.13;
-
-
access_log logs/13-80.host.access.log main;
-
-
location / {
-
root html;
-
index index.html index.htm;
-
}
-
-
error_page 500 502 503 504 /50x.html;
-
location = /50x.html {
-
root html;
-
}
-
}
-
-
#======balance 8800======= 如果访问::8800,则会跳转到内部网络的windows 2/3
-
upstream balance
-
{
-
server 192.168.10.2:9900;
-
server 192.168.10.3:9901;
-
}
-
#========server 8800-> balance 2/3
-
server {
-
listen 8800;
-
server_name 60.x.x.13; 域名
-
-
access_log logs/58.host.access.log main;
-
-
location / {
-
proxy_pass #此处跟upstream balance名称对应
-
proxy_set_header Host $host;
-
proxy_set_header X-Real-IP $remote_addr;
-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
-
}
-
-
error_page 500 502 503 504 /50x.html;
-
location = /50x.html {
-
root html;
-
}
-
}
-
}
-------------------------------
重启nginx服务, #/usr/local/nginx/sbin/nginx -s reload
客户端刷新访问::8800 看是不是分别对应到192.168.10.2/3网站内容了。(2/3的页面内容设置不一样就可以查看出来)
阅读(833) | 评论(0) | 转发(0) |