location /images/ {
root /data/www;
error_page 404= /fetch$uri;
}
location /fetch {
inertnal;
fastcgi_pass backend;
fastcgi_store on;
fastcgi_store_access user:rw group:rw all:r;
fastcgi_temp_path /data/temp;
alias /data/www;
}
fastcgi_srote_access 用于指定创建文件或目录的权限
反代 本机端口
location / {
proxy_pass http://127.0.0.1:8081;
#proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
client_max_body_size 1m;
}
反代以 xx 前缀开头
location ^~ /xx/ {
default_type text/html;
proxy_pass https://other.xxx.cn/;
}
不区分大小写匹配 满足前缀格式 301跳转
location ~* ^/data/attachment/(.+) {
return 301 https://xxx.domain.la/res/data/attachment/$1;
}
大小写匹配 禁止目标文件访问
location ~ /config.txt {
return 404;
}
前缀匹配反代后全局替换文本内容
location ^~ /proxy/ {
default_type text/html;
proxy_pass https://other.domain.com/;
proxy_set_header MY-PROXY yes;
replace_filter /api.php /proxy/api.php g;
replace_filter /source/api/ /proxy/source/api/ g;
}
返回JSON数据 替换文本
replace_filter_types application/json;
replace_filter '明星' '渣男' 'g';