我找不到有关如何使用nginxpipe理cookie的信息
我已经看到,两个variables是cookie的亲属,即$ http_cookies和$ cookie_COOKIENAME。
无论如何,我绝对不知道如何用nginx读取cookie。
例如,如果一个具有特殊值的cookie存在,我想返回一个403,我试过了,但是这似乎不起作用:
if ($cookie_mycookiename = "509fd1e420bba") { return 403; }
也尝试使用$ http_cookie
if ($http_cookie = "509fd1e420bba") { return 403; }
我真的不明白nginx如何处理cookie …
编辑这里是我的完整的nginxconfiguration
server { listen 80; root /home/minou/vids/; index index.html index.htm; #server_name localhost; location / { # First attempt to serve request as file, then # as directory, then fall back to index.html try_files $uri $uri/ /index.html; if ($cookie_fileURI = "6509fd1e420bba") { return 403; } } # anti hotlinking location ~* \.(jpg)$ { valid_referers none blocked mywebsite.com www.mywebsite.com; if ($invalid_referer) { return 403; } } }
请注意, if在某个location使用不正常,特别是在与try_files一起使用时。 请参阅: http : //wiki.nginx.org/IfIsEvil
请试试这个:
server { listen 80; root /home/minou/vids/; index index.html index.htm; #server_name localhost; if ($cookie_fileURI = "6509fd1e420bba") { return 403; } location / { # First attempt to serve request as file, then # as directory, then fall back to index.html try_files $uri $uri/ /index.html; } # anti hotlinking location ~* \.(jpg)$ { valid_referers none blocked mywebsite.com www.mywebsite.com; if ($invalid_referer) { return 403; } } }