2017-12-13 20 views
0

나는 이것이 기본적인 것들의 종류 생각 라우팅,하지만 난이 일을 설명 할 적절한 가이드 찾기 위해 사투를 벌인거야 : https://dev.something.com 확인을 작동하도록 내가 index.php 파일 nginx 설정이Nginx의 URL은

합니다.

그러나 nginx 구성을 변경해야 해당 주소에서 빈 페이지가 생성되고 index.phphttps://dev.something.com/lists에서만 작동합니다. 나는 목록 디렉토리 안에 index.php을 넣을 수 있지만 더 미묘한 해결책이 아닌가요?

그리고 여기에 하드 부분 : 사용자

https://dev.something.com/lists/userName 
https://dev.something.com/lists/userName/listName 

userNamelistNameGET -parameters 표기에 액세스 할 수 있어야합니다.

아무도 nginx으로 어떻게 구성 할 수 있습니까?

답변

0

당신은 몇 가지 (상대적으로 기본) 질문을하고, 나는 당신이 그들의 무료 전자 책으로 시작하는 것이 좋습니다 것입니다 https://www.nginx.com/blog/announcing-oreillys-new-book-nginx-a-practical-guide-to-high-performance/

nginx를 루트 절을 사용하여 인덱스 파일을 어디 당신은 정의 할 수 있습니다, 그들은 비록 일반적으로 server의 루트와 관련된 URL 컨텍스트를 사용하면 각 위치에서 재정의 할 수 있습니다.

http://nginx.org/en/docs/http/ngx_http_core_module.html#root

너무 paramters으로 전달 될 수있는 변수로 URL 중 일부를 사용할 수 있습니다.

location = /lists { # '=' will match exactly, no trailing url 
     root /path/where/index.php/lives; 
     try_files $uri /index.php; 
    } 
    location /lists { # this will match anything under that url 
     rewrite ^/lists/(\d+)/?$ /lists?user=$1; # matches username 
     rewrite ^/lists/(\d+)/(\d+)/?$ /lists?user=$1&list=$2; # matches username/list 
    } 

    location /{ #everything else 
     root /path/where/index.html/lives; #index.html is empty file. 
     try_files $uri /index.html; 
    } 
+0

고마워요! 거의 작동하지만, 예제에서는 매개 변수 사용을 숫자로 제한한다고 생각하십니까? 그리고 어떤 이유로'$ _GET' 배열이 비어 있습니까? –

+0

그래, 나는 사용자/목록 ID를 추측하고 있었지만 \ d를 의미가있는 정규식 캡처 그룹으로 바꿀 수는있다. 추가 인수가있는 경우 다시 쓰기 인수 끝에 query_string'? & query_string; 변수를 추가 할 수 있습니다. – Eddie