我需要通过nginx为用户提供一些文件。用户的请求URL与服务器中的真实文件路径之间的位置不同。所以我尝试在位置使用别名
请求网址:
1)http://info.myservice.com/statement/ 12345678 /12/34/A.html
2)http://info.myservice.com/statement/ 57837873 /56/78/B.html
...
服务器中的实际路径:
1)/data/statement/0/12/34/A.html
2)/data/statement/0/56/78/B.html
位置设置:
location ~ /statement/[0-9]+ {
if ($request_uri ~ "/(d+|-)(.*)") {
#access_log off;
access_log /var/log/nginx/access.log main;
}
alias /data/statement/0;
}
但它不起作用。需要一些建议..
感谢。
答案 0 :(得分:0)
您可以使用root
指令和rewrite ... break
来使网址与实际路径匹配:
location /statement/ {
root /data/statement/0;
rewrite ^/statement/[0-9]+(/.*)$ $1 break;
}
有关详细信息,请参阅this document。