1.配置反向代理
编辑配置nginx 配置文件,在安装目录下找到nginx.conf 配置如下代码
–反向代理:proxy_pass ip:port[uri];
server {
listen 80;
server_name www.360.com;
location /{
root /mnt;
autoindex on;
}
}
server {
listen 80;
server_name www.sxthenhao.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
location /ooxx.go {
proxy_pass http://192.168.227.12/; //反向代理服务器
}
}
其中server 配置的是多个服务端,listen 配置的是需要请求的端口,server_name则是配置访问的域名, location 配置过滤规则
location 映射(ngx_http_core_module)
location [ = | ~ | ~* | ^~ ] uri { ... }
location URI {}:
对当前路径及子路径下的所有对象都生效;
location = URI {}: 注意URL最好为具体路径。
精确匹配指定的路径,不包括子路径,因此,只对当前资源生效;
location ~ URI {}:
location ~* URI {}:
模式匹配URI,此处的URI可使用正则表达式,~区分字符大小写,~*不区分字符大小写;
location ^~ URI {}:
不使用正则表达式
优先级:= > ^~ > ~|~* > /|/dir/
/loghaha.html
/logheihei.html
^/log.*html$
2.配置负载均衡
(1)在nginx.config文件中配置
upstream bula{
server 192.168.227.12;
server 192.168.227.13;
}
其中server 是需要负载均衡的服务器 bula 为随意起的名字
(2)将服务器的llocation 的转发proxy_pass 接口改为 定义的负载均衡服务器组的名字
(3)禁止会话保持
keeplive_timrout 设置为0
重启nginx 加载配置文件
[root@node01 conf]# service nginx reload
访问 实验
第一次访问
第二次访问