有一个更好的方法吗? 我无法find一种方法来嵌套或应用boolean操作符到nginx中的条件。
基本上,如果有一个cookie集(非匿名用户),我们要打服务器。 如果cookie没有设置并且文件存在,我们想要服务器文件,否则命中服务器。
set $test "D"; if ($http_cookie ~* "session" ) { set $test "${test}C"; } if (-f $request_filename/index.html$is_args$args) { set $test "${test}F"; } if ($test = DF){ rewrite (.*)/ $1/index.html$is_args$args? break; } if ($test = DCF){ proxy_pass http://django; break; } if ($test = DC){ proxy_pass http://django; break; } if ($test = D){ proxy_pass http://django; break; }
location / { if ($cookie_session) { proxy_pass http://django; } try_files $uri/index.html$is_args$args @django; } location @django { proxy_pass http://django; }
location / { if ($cookie_session) { rewrite ^ /django/; } if (-f $request_filename/index.html$is_args$args) { rewrite (.*)/ $1/index.html$is_args$args; #did you mean ; instead of ? } proxy_pass http://django; } location /django/ { proxy_pass http://django; }
不知道是否好得多,但避免使用在if语句中被认为不安全的事物。