2017-12-23 2 views
2

어떻게 nginx 서버의 구성을 올바르게 쓸 수 있습니까?NGINX의 사용자 에이전트에 의해 다른 파일

... 
if the client has useragent (A) and it refers to http://somehost.domain/somefile.someextension 
     nginx responding a file from the root /file.zip 
if the client has useragent (B) and it refers to http://somehost.domain/somefile.someextension 
     nginx responding a file from the root /file2.zip 
if the client has useragent (C) and it refers to http://somehost.domain/somefile.someextension 
     nginx responding 403 error 
... 

이 코드했다 :

map $http_user_agent $browser { 
     "~*Firefox"    "/var/www/test1"; 
     "~*Wget"    "/var/www/test2"; 
     "~*SomeUserAgent"  "/var/www/test3"; 
} 

server { 
... 
root $browser 

을하지만 어떻게 조건이 모든 주소 http://somehost.domain/somefile.someextension로 전달받을 수 있나요?

답변

0

map, locationalias 지시문을 사용하면 특정 URI를 헤더 값을 기반으로 여러 파일에 매핑 할 수 있습니다. (모든 파일이 동일 디렉토리에) 예를 들어

는 :

map $http_user_agent $browser { 
    default   "nonexistent"; 
    "~*Firefox"  "file.zip"; 
    "~*Wget"   "file1.zip"; 
} 

server { 
    ... 
    location = /somefile.someextension { 
     alias /path/to/directory/$browser; 

     if (!-f $request_filename) { 
      return 403; 
     } 
    } 
} 

if 블록은 403 응답에 대한 응답 (404)을 변경할 필요가있다.

자세한 내용은 this document을 참조하십시오.

관련 문제