
我正在使用 X-Accel 來提供包含圖像的受保護資料夾:https://www.nginx.com/resources/wiki/start/topics/examples/x-accel/
目前我將文件儲存在/protected_files
資料夾中。現在,為了使用 X-Accel 查看文件,我傳遞了包含 URL 的路徑/protected_files
,例如protected_files/image1.jpg
.
這就是我對受保護資料夾設定保護的方法:
location /protected_files {
internal;
}
然後,為了使用 X-Accel 查看文件,我傳遞了帶有X-Accel-Redirect
.
有沒有辦法封鎖 URL,看起來像是從另一個 URL 提供的?喜歡/fake_folder/image1.jpg
?
我嘗試過但沒有成功的是使用所需的假名創建另一個資料夾,然後將別名添加到真實名稱:
location /fake_folder {
internal;
alias /protected_files;
}
然後我用 傳遞 URL /fake_folder/image1.jpg
,但出現錯誤 404
答案1
根據文件對於內部,重寫的請求算內部請求。以下應該有效:
location /fake_folder {
rewrite ^/fake_folder/(.*)$ /protected_files/$1 break;
}