2013-11-15 2 views
2

사용자가 루트 (일명 /) URL로 특정 도메인에 액세스 할 때 URL을 다시 작성해야합니다. 지금까지 내가 가지고있는 것 :NGINX 특정 도메인 및 특정 URL이있는 경우 URL 다시 쓰기

server { 
    listen 80; 
    server_name name1.com name2.com; 

    location =/{ 
    # Well, I need this only for NAME2.COM (it should not rewrite NAME1.COM) 
    rewrite name2.com/users/sign_in 
    } 
} 

NAME2.COM에 대해서만 재 작성 방법. 때로는 NGINX 구문을 사용하여 스택 오버플로가 발생합니다. 도와주세요.

답변

2

서버 블록을 분할해야합니다. 참조 : 당신은 if을 사용하십시오 http://wiki.nginx.org/Pitfalls

server { 
    listen 80; 
    server_name name1.com; 

    location =/{ 
    # no rewrite here 
    } 
} 

server { 
    listen 80; 
    server_name name2.com; 

    location =/{ 
    # your rewrite here 
    } 
} 
1

, 다음과 같이 :

server { 
    listen 80; 
    server_name name1.com name2.com; 

    location =/{ 
    if ($host = name2.com) { 
     rewrite^/users/sign_in last; 
    } 
    } 
}