通
Nginx 源码编译安装,使其支持4层,并监听80端口
[root@lb-node1 ~]# useradd -s /sbin/nologin -M www [root@lb-node1 ~]# cd /usr/local/src/ [root@lb-node1 src]# wget http://nginx.org/download/nginx-1.10.2.tar.gz [root@lb-node1 src]# tar xf nginx-1.10.2.tar.gz [root@lb-node1 src]# cd nginx-1.10.2 [root@lb-node1 nginx-1.10.2]# ./configure --prefix=/usr/local/nginx-1.10.2 \ --user=www --group=www --with-http_ssl_module \ --with-http_stub_status_module --with-file-aio --with-stream [root@lb-node1 nginx-1.10.2]# make && make install [root@web-node1 ~]# ln -s /usr/local/nginx-1.10.2/ /usr/local/nginx ## 测试配置并启动Nginx [root@lb-node1 ~]# /usr/local/nginx/sbin/nginx -t nginx: the configuration file /usr/local/nginx-1.10.2/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx-1.10.2/conf/nginx.conf test is successful [root@lb-node1 ~]# /usr/local/nginx/sbin/nginx
配置Nginx反向代理
##http段配置 upstream web-cluster { # ip_hash; server 192.168.90.201:8080 weight=1 max_fails=3 fail_timeout=3; server 192.168.90.202:8080 weight=1 max_fails=3 fail_timeout=3; } server { listen 80; server_name 192.168.90.203; location / { proxy_pass http://web-cluster; include proxy.conf; } }
测试代理
[root@lb-node1 ~]# curl http://192.168.90.203/ web-node1.com [root@lb-node1 ~]# curl http://192.168.90.203/ web-node2.com [root@lb-node1 ~]# curl http://192.168.90.203/ web-node1.com [root@lb-node1 ~]# curl http://192.168.90.203/ web-node2.com
通过分组方式,以及User-agent实现不同代理
#http段配置 upstream static-cluster { server 192.168.90.201:8080 weight=1 max_fails=3 fail_timeout=3; } upstream dynamic-cluster { server 192.168.90.202:8080 weight=1 max_fails=3 fail_timeout=3; } upstream default-cluster { server 192.168.90.202:8080 weight=1 max_fails=3 fail_timeout=3; } #需要配置本地host解析测试 server { listen 80; server_name nginx.xuliangwei.com; location / { if ($http_user_agent ~* "Firefox"){ proxy_pass http://static-cluster; } if ($http_user_agent ~* "Chrome") { proxy_pass http://dynamic-cluster; } proxy_pass http://default-cluster; } }
继续阅读
- 我的QQ
- QQ扫一扫
-
- 我的头条
- 头条扫一扫
-
评论