[root@lb01 nginx]# systemctl reload nginx
>
> 记得将之前环境中的其他模块一起修改或暂时注释掉,不然语法会报错
>
>
>
>
> #### 2.curl一下查看结果
>
>
> curl -A 可以指定系统
>
>
>
[root@lb01 nginx]# curl 10.0.0.5/lidao.html this is PC website [root@lb01 nginx]# curl -A ios 10.0.0.5/lidao.html this is Mobile website [root@lb01 nginx]# curl -A Android 10.0.0.5/lidao.html this is Mobile website
#### 3.可以下载火狐浏览器查看
>
> <http://www.firefox.com.cn/>
> 安装插件流程:
> 
>
>
>
## 三、根据 URI 中的目录地址实现代理转发(动静分离)
>
> 添加一台测试web03节点—10.0.0.9
> 将web03的配置与web01和web02配置相同
> (/app站点目录与nginx.conf配置文件)
>
>
>
>
> 
> 
>
>
>
#### 1.准备环境
www.oldboy.com/upload/inde… www.oldboy.com/static/inde… www.oldboy.com/index.html
#web01: mkdir -p /app/www/upload/index.html echo this is upload >/app/www/index.html [root@web01 ~]# cat /app/www/upload/index.html this is upload
#web02: mkdir -p /app/www/static/index.html echo this is static >/app/www/index.html [root@web02 ~]# cat /app/www/static/index.html this is static
#web03: mkdir -p /app/www/index.html #之前已经有首页文件,只需修改内容 echo this is default >/app/www/index.html [root@web03 ~]# cat /app/www/index.html this is default
#### 2.配置 upstream 与location
>
> 定义upstream.
>
>
>
upstream upload {
server 10.0.0.7:80 weight=1 max_fails=3 fail_timeout=10s;
}
upstream static {
server 10.0.0.8:80 weight=1 max_fails=3 fail_timeout=10s;
}
upstream default {
server 10.0.0.9:80 weight=1 max_fails=3 fail_timeout=10s;
}
>
> 添加location
>
>
>
server {
listen 80;
server_name www.oldboy.com;
location /upload {
proxy_pass http://upload;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote\_addr;
}
location /static {
proxy_pass http://static;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote\_addr;
}
location /default {
proxy_pass http://default;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote\_addr;
}
}
>
> 完整配置
> 
>
>
>
[root@lb01 nginx]# vim nginx.conf .... upstream upload { server 10.0.0.7:80 weight=1 max_fails=3 fail_timeout=10s; } upstream static { server 10.0.0.8:80 weight=1 max_fails=3 fail_timeout=10s; } upstream default { server 10.0.0.9:80 weight=1 max_fails=3 fail_timeout=10s; }
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
server_name www.oldboy.com;
location /upload {
proxy_pass http://upload;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote\_addr;
}
location /static {
proxy_pass http://static;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote\_addr;
}
location / {
proxy_pass http://default;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote\_addr;
}
}
} [root@lb01 nginx]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful [root@lb01 nginx]# systemctl reload nginx
#### 3.浏览器测试一下
>
> 上传静态动态(默认)
>
>
>
---
## 四、轮询算法

>
> ip\_hash
> 只要客户端ip地址相同就会被转发到同一台机器上
> 
>
>
>
## 六、cookie与session会话区别
>
> 会话保持
> cookie
> session
>
>
>
#### 1.共同点
>
> 存放用户信息
> key value类型 变量和变量内容
>
>
>
### 最后的话
最近很多小伙伴找我要Linux学习资料,于是我翻箱倒柜,整理了一些优质资源,涵盖视频、电子书、PPT等共享给大家!
### 资料预览
给大家整理的视频资料:

给大家整理的电子书资料:

**如果本文对你有帮助,欢迎点赞、收藏、转发给朋友,让我有持续创作的动力!**
详情docs.qq.com/doc/DSmdCdUNwcEJDTXFK