2014-04-06 3 views
1

내 폴더 구조는 다음과 같습니다- 다음과 같이 Nginx에

/www 
    /api.domain.tld 
    /app.domain.tld 

API는 시스템 그 자체를 포함하고 APP는 HTTP를 통해 API를 구현합니다.

API 용 "가상 디렉터리"가 포함 된 app.domain.tld 용 Nginx 서버를 만들고 싶습니다. http://api.domain.tld/method/api.json

그러나이 API는 다음과 같이 연락 할 수 있다면 좋을 것 :

당신은 API를 문의 할 수 있습니다이 좋아 APP에 뭔가를 복사하지 않고 http://app.domain.tld/api/method/api.json하지만,이 두 "시스템"분리를 유지한다. 내가 지금이

: 예상대로 불행하게도이 지금 수행

server { 
    listen 80; 
    root /var/www/app.domain.tld; 
    index index.php index.html; 


    server_name app.domain.tld; 


    location ^~ /api { 
     alias /var/www/api.domain.tld; 


     location ~ \.php$ { 
      try_files $uri = 404; 
      fastcgi_pass unix:/var/run/php5-fpm.sock; 
      fastcgi_index index.php; 
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
      include fastcgi_params; 
     } 


     rewrite ^/api/([a-z]+)/api.json$ /api.php?method=$1 last; 
    } 


    location.... 
    location.... 
    location.... 


    location ~ \.php$ { 
     try_files $uri = 404; 
     fastcgi_pass unix:/var/run/php5-fpm.sock; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     include fastcgi_params; 
    } 
} 

작동합니다.

다시 쓰기가 전혀 작동하지 않습니다. api.domain.tld/index.php를 얻을 수 있지만 재 작성을 사용해야하는 경우 작동하지 않습니다.

나는 여러 가지를 시도했다. 40435 또는 403에이 오류가 표시됩니다. [경로]의 디렉토리 색인이 금지되어 있습니다.

누군가가 실제로 더 효과적인 해결책을 제시 할 수 있습니까?

감사

당신은 SCRIPT_FILENAME 경로를 변경해야합니다

답변

2

:

server { 
    listen 80; 
    root /var/www/app.domain.tld; 
    index index.php index.html; 

    location ~ ^/api/(.+\.php)$ { 
     alias /www/api.domain.tld/public/$1; 
     fastcgi_pass 127.0.0.1:9000; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $request_filename; 
     include fastcgi_params; 
    }  
}