2014-09-26 59 views
0

我正在嘗試配置nginx。如果我輸入http://localhost/dav,它應該在location /dav指令中使用來自配置爲root(c:/ wt-nmp/www/app-dav/frontend/web)的index.php腳本。但是當我調試nginx時,它仍然使用配置爲server配置的root更改不同請求上的nginx根

在調試,它看起來像:

  1. 它採用location /dav並設置root新的價值和改變index.php?dav
  2. 現在使用location ~ \.php$$document_root仍指向c:/wt-nmp/www/m24/web,但我認爲它應該改變在location /dav正如第1點所述。

我的問題是如何配置nginx使用腳本從c:/wt-nmp/www/app-dav/frontend/web當我輸入http://localhost/dav

我覺得這個代碼應該像那:

  1. rootserver指令當我輸入網址http://example.com/dav然後指令location /dav應該從該位置改變root.../m24/app-dav/frontend/web和PHP腳本設置爲.../m24/web
  2. 應該執行。
  3. 但是,當我調試這個應用程序,腳本.../m24/web仍然執行。 location /dav爲什麼root指令不會更改$document_root值。 $document_root仍然指向.../m24/web

我的配置中最重要的部分是這樣的:

server { 
    ... 

    root "c:/wt-nmp/www/m24/web"; 
    index index.html index.htm index.php; 

    location /dav { 
     root "c:/wt-nmp/www/m24/app-dav/frontend/web"; 
     # The $uri gets mangled by nginx, however Yii urlmanager requires REQUEST_URI to route 
     set $original_uri $uri?$args; 
     # Try the actual uri, then uri as a directory, then send it to yii 
     try_files $uri $uri/ /index.php?$args; 
    } 

    location/{ 
     #set original_uri to use as the request_uri later on 
     #The $uri gets mangled by nginx, however Yii urlmanager requires REQUEST_URI to route 
     set $original_uri $uri?$args; 
     #Try the actual uri, then uri as a directory, then send it to yii 
     try_files $uri $uri/ /index.php?$args; 
    } 

    location ~ \.php$ { 
     fastcgi_pass     php_farm; 
     include      nginx.fastcgi.conf; 
     fastcgi_split_path_info  ^(.+\.php)(/.+)$; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     fastcgi_param REQUEST_URI  $original_uri; 
    } 
} 
+1

你可以在得到這個更好的反應過[服務器故障(http://serverfault.com/)。 – DavidT 2014-09-26 10:07:48

+0

完成。我應該刪除這個問題嗎? – marag 2014-09-26 11:34:41

+0

海事組織其實並非這個網站的主題,只是想更多的人可以在SF上回答。 – DavidT 2014-09-26 11:46:31

回答

0

你應該有2級位置的指令,一個PHP文件/dav下,另一個用於靜態文件/dav下:

location ~ ^/dav/.*\.php$ {     
     root "c:/wt-nmp/www/app-dav/frontend"; 
     try_files $uri =404; 
     include  nginx.fastcgi.conf; 
     fastcgi_pass php_farm; 
} 

location ~ ^/dav/ { 
     root "c:/wt-nmp/www/app-dav/frontend"; 
} 

這樣的文件將從c:/wt-nmp/www/app-dav/frontend/dav提供。所以你可能也想rename c:/wt-nmp/www/app-dav/frontend/web c:/wt-nmp/www/app-dav/frontend/dav,因爲URL路徑必須匹配根子目錄!

此外,請確保您使用最新版本的WT-NMP - portable Nginx Mysql Php development stack for Windows`

+0

感謝您的回覆。我不認爲這會解決我的問題。我編輯了我的帖子,爲您提供更多信息,我試圖實現。 – marag 2015-04-15 09:33:21