[英]Nodejs, nginx, express - Checking if user is authenticated before serving static files doesn't work
使用nginx運行時,app.get似乎沒有受到攻擊。 但是,它在本地運行,沒有nginx。 受影響的代碼如下:
app.get('/', function(req, res, next){
if (!req.isAuthenticated()){
return res.redirect('/login');
} else {
app.use('/', express.static(path.join(__dirname, 'dist-restricted')));
return next();
}
});
該代碼在向用戶發送受限制的靜態文件之前,會檢查用戶是否已使用護照進行了身份驗證。 運行nginx時,不會重定向用戶登錄。
Nginx是否與此有關? 以及我該如何解決。
您的nginx可能在不通過節點的情況下提供靜態文件。
例如,使用這樣的配置,nginx將直接讀取文件,而無需使用node:
location ~^\/(js|css|fonts|images|img|plugins|upload|pdf) {
expires 1M;
access_log off;
add_header Cache-Control "public";
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods GET;
add_header Access-Control-Allow-Headers X-Requested-With,content-type;
add_header Access-Control-Allow-Credentials true;
root /mypatht/public;
}
如果nginx直接讀取您的文件夾,則不編輯nginx配置就無法做任何事情。
要確保將console.log放入app.get內,如果未出現,則必須編輯nginx
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.