Nginx动静分离、upload

1 根据目录设置动静分离
#定义反向代理的静态池和动态池、上传服务器池
upstream jingtai_web {
server 10.125.192.6:80 weight=1;
server 10.125.192.7:80 weight=1;
}

upstream dongtai_web {
server 10.125.192.20:80 weight=1;
server 10.125.192.21:80 weight=1;
}

upstream upload_data {
server 10.125.192.60:80
server 10.125.192.61:80
}

server {
listen 80;
server_name www.aaa.com;
location / {
root html;
index index.php index.html
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME d o c u m e n t r o o t document_root fastcgi_script_name;
include fastcgi.conf;
proxy_pass http://dongtai_web; #当访问uri中没有image和upload就交给dongtai处理
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
}
location /image/ { #(当客户访问的uri中含有image就交给此行处理,交给jingtai池服务器处理)
porxy_pass http://jingtai_web;
}
location /upload/ {
proxy_pass http://upload_data;
}
}

2 通过扩展名动静分离
upstream jingtai_web {
server 10.125.192.6:80 weight=1;
server 10.125.192.7:80 weight=1;
}

upstream dongtai_web {
server 10.125.192.20:80 weight=1;
server 10.125.192.21:80 weight=1;
}

upstream upload_data {
server 10.125.192.60:80
server 10.125.192.61:80
}

server {
listen 80;
server_name www.aaa.com;
location / {
root html;
index index.php index.html
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME d o c u m e n t r o o t document_root fastcgi_script_name;
include fastcgi.conf;
proxy_pass http://dongtai_web;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For KaTeX parse error: Expected 'EOF', got '}' at position 16: remote_addr; }̲ location ~* .… {
porxy_pass http://jingtai_web;
}
location /upload/ {
proxy_pass http://upload_data;
}
}

反向代理,利用请求方法实现上传和读分离
location / {
proxy_pass http://10.125.192.5;
if ($request_method = ”PUT”) {
proxy_pass http://10.125.192.6;
}
}

猜你喜欢

转载自blog.csdn.net/bjgaocp/article/details/87886467