💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# 上传和访问资源池分离 [TOC] ## 一、需求梳理: **1.需求** * 当用户请求`www.etiantian.org/upload/xx `地址时,实现由upload上传服务器池处理请求。 * 当用户请求`www.etiantian.org/static/xx` 地址时,实现由静态服务器池处理请求。 * 除此以外,对于其他访问请求,全都由默认的动态服务器池处理请求。 **2.资源池** |用户请求[URI]|处理请求服务器|站点目录|功能| | --- | --- | --- | --- | |/upload|10.0.0.8:80|html/www/upload|upload服务器| |/static|10.0.0.7:80|html/www/static|static静态服务器| |/|10.0.0.9:80|html/www|默认| **3.环境搭建** ```sh yum install nginx -y egrep -v "#|^$" /etc/nginx/nginx.conf.default >/etc/nginx/nginx.conf mkdir -p /data/html/www cp /usr/share/nginx/html/* /data/html/www sed -ri '/^$|#/d' /etc/nginx/nginx.conf sed -ri '/^$|#/d' /etc/nginx/conf.d/default.conf 省略 ``` ## 二、处理方法: ### 1.完成nginx网站服务器配置 **创建测试环境** 10.0.0.8 主机上创建upload目录,然后生成网站测试页面文件 ```sh mkdir -p /data/html/www/upload echo "test in Ip 10.0.0.8 is upload" >/data/html/www/upload/noah.html ``` 10.0.0.7 主机上创建static目录,然后生成网站测试页面文件 ```sh mkdir -p /data/html/www/static echo "test in Ip 10.0.0.7 is static" >/data/html/www/upload/noah.html ``` 10.0.0.9 主机上创建默认测试页面文件即可 ```sh echo "test in Ip 10.0.0.9 is default" >/data/html/www/noah.html ``` ### 2.利用lb01进行访问测试 测试10.0.0.8访问是否正常 ```sh curl -H host:www.etiantian.org 10.0.0.8/upload/noah.html web02 www.etiantian.org ``` 测试10.0.0.7访问是否正常 ```sh curl -H host:www.etiantian.org 10.0.0.7/static/noah.html web01 www.etiantian.org ``` 测试10.0.0.9访问是否正常 ```sh curl -H host:www.etiantian.org 10.0.0.9/noah.html web03 www.etiantian.org ``` ### 3.完成nginx反向代理服务器配置 1)配置upstream模块信息 ```sh upstream upload { server 10.0.0.8:80; } upstream static { server 10.0.0.7:80; } upstream default { server 10.0.0.9:80; } ``` 2)配置proxy_pass模块信息 ```sh server { listen 80; server_name www.etiantian.org; root html; index index.html index.htm; location / { proxy_pass http://default; proxy_set_header host $host; proxy_set_header X-Forwarded-For $remote_addr; } 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; } } ```