【发布时间】:2014-09-26 10:00:47
【问题描述】:
我正在尝试配置 nginx。如果我输入http://localhost/dav,它应该在location /dav 指令中使用配置的root (c:/wt-nmp/www/app-dav/frontend/web) 中的index.php 脚本。但是当我调试 nginx 时,它仍然使用在server 配置中配置的root。
在调试中它看起来像:
- 它使用
location /dav并将root设置为新值并更改为index.php?dav - 现在它使用
location ~ \.php$,但$document_root仍然指向c:/wt-nmp/www/m24/web,但我认为它应该在location /dav中进行更改,如第1 点所述。
我的问题是当我输入http://localhost/dav时如何配置nginx使用来自c:/wt-nmp/www/app-dav/frontend/web的脚本。
我认为这段代码应该是这样工作的:
-
root从server指令设置为.../m24/web - 当我输入 url
http://example.com/dav时,指令location /dav应该将root更改为.../m24/app-dav/frontend/web,并且应该执行该位置的 php 脚本。 - 但是当我调试这个应用程序时,来自
.../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;
}
}
【问题讨论】:
-
你可能会在server fault得到更好的回应。
-
完成。我应该删除这个问题吗?
-
IMO 对这个网站来说实际上并不是题外话,只是想更多的人能够在 SF 上回答。