Chinaunix首页 | 论坛 | 博客
  • 博客访问: 577670
  • 博文数量: 94
  • 博客积分: 1452
  • 博客等级: 上尉
  • 技术积分: 982
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-06 15:38
文章分类

全部博文(94)

文章存档

2018年(3)

2014年(26)

2013年(11)

2012年(3)

2011年(43)

2010年(8)

分类: 架构设计与优化

2013-05-31 14:06:36

参考:
      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  -----------------------------------

点击(此处)折叠或打开

  1. #user nobody;
  2. worker_processes 1;

  3. error_log logs/error.log;
  4. #error_log logs/error.log notice;
  5. #error_log logs/error.log info;

  6. pid logs/nginx.pid;


  7. events {
  8. use epoll;
  9. worker_connections 1024;
  10. }


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

  14. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  15. '$status $body_bytes_sent "$http_referer" '
  16. '"$http_user_agent" "$http_x_forwarded_for"';

  17. access_log logs/access.log main;

  18. sendfile on;
  19. #tcp_nopush on;

  20. #keepalive_timeout 0;
  21. keepalive_timeout 65;
  22. tcp_nodelay on;

  23. #gzip on;
  24. gzip on;
  25. gzip_disable "MSIE [1-6]\.(?!.*SV1)";

  26. #========= server 80 ====== 如果访问centos 80端口是访问到nginx代理服务器自身的站点
  27. server {
  28. listen 80;
  29. #有域名可用域名
  30. server_name 60.x.x.13;

  31. access_log logs/13-80.host.access.log main;

  32. location / {
  33. root html;
  34. index index.html index.htm;
  35. }

  36. error_page 500 502 503 504 /50x.html;
  37. location = /50x.html {
  38. root html;
  39. }
  40. }

  41. #======balance 8800======= 如果访问::8800,则会跳转到内部网络的windows 2/3
  42. upstream balance
  43. {
  44. server 192.168.10.2:9900;
  45. server 192.168.10.3:9901;
  46. }
  47. #========server 8800-> balance 2/3
  48. server {
  49. listen 8800;
  50. server_name 60.x.x.13; 域名

  51. access_log logs/58.host.access.log main;

  52. location / {
  53. proxy_pass #此处跟upstream balance名称对应
  54. proxy_set_header Host $host;
  55. proxy_set_header X-Real-IP $remote_addr;
  56. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  57. }

  58. error_page 500 502 503 504 /50x.html;
  59. location = /50x.html {
  60. root html;
  61. }
  62. }
  63. }


 -------------------------------
重启nginx服务, #/usr/local/nginx/sbin/nginx -s reload

客户端刷新访问::8800 看是不是分别对应到192.168.10.2/3网站内容了。(2/3的页面内容设置不一样就可以查看出来)








阅读(5203) | 评论(2) | 转发(2) |
给主人留下些什么吧!~~