%EB%A5%BC%20%EA%B8%B0%EB%B0%98%EC%9C%BC%EB%A1%9C%20try_files%EB%A5%BC%20%EC%82%AC%EC%9A%A9%ED%95%98%EC%97%AC%20%EB%8B%A4%EC%96%91%ED%95%9C%20%ED%8C%8C%EC%9D%BC%EC%9D%84%20%EC%A0%9C%EA%B3%B5%ED%95%A9%EB%8B%88%EB%8B%A4..png)
다음과 같이 nginx 서버를 구성해야 합니다. 사용자에게 특정 쿠키가 있어서 서버가 파일을 보내야 하고, 그렇지 않으면 서버가 다른 쿠키를 보내야 합니다. 관련 기사를 많이 읽었지만 도움이 되지 않았습니다. 또한 try_files
회의 시 몇 가지 문제가 있다는 것을 알고 있지만 location if
이를 해결하는 방법은...
작동해야 하지만 실제로는 작동하지 않는 예가 있습니다.
upstream site {
server localhost:4321;
}
server {
listen *:1234;
server_name site.com;
root /path/www/;
ssl on;
ssl_certificate /path/ssl.crt;
ssl_certificate_key /path/ssl.key;
location = / {
set $variable /path/index.html;
if ($http_cookie ~* "someCookie=someValue(?:;|$)") {
set $index_file /path2/index.html;
}
rewrite .* $index_file break;
try_files $uri/index.html $uri.html $uri @site;
}
}
답변1
다음과 같이 시도해 보세요.
if ($cookie_myCookieNameIsBlaBlaBla ~* "cookieValueThatIWannaMatch") {
# my logic in here
}
nginx의 문서에 따르면 if는 악하므로 주의하세요.
더 많은 정보:
- http://nginx.org/en/docs/http/ngx_http_rewrite_module.html
- https://www.nginx.com/resources/wiki/start/topics/깊이/ifisevil/
시아!
답변2
최선의 해결책은 확실하지 않지만 이런 식으로 수행했지만 작동합니다.
location @rewrite {
if ($http_cookie ~* "someCookie=someValue(?:;|$)") {
rewrite .* /path1/file1.html last;
}
rewrite .* /path2/file2.html last;
}
location = / {
try_files $uri/index.html $uri.html $uri @rewrite;
}