我正在尝试使用php-fpmconfigurationnginx,所以大多数请求都被传递给一个单独的php脚本。
目录布局如下:
assets/... index.php
我希望这些url的工作方式如下:
/ -> index.php /foo -> index.php /bar/baz?spam=ham -> index.php /assets -> assets folder
index.php应该将PATH_INFO设置为'/' , '/foo'和'/bar/baz' 。
我已经想出了最接近的configuration如下:
location / { try_files $uri /index.php/$uri$is_args$args; } location /assets { try_files $uri =404; } location /index.php { include snippets/fastcgi-php.conf; include fastcgi_params; fastcgi_pass unix:/var/run/php5-fpm.sock; }
但是, PATH_INFO总是有一个额外的/ (例如在第一种情况下的'//' )。 更改为/index.php$url$is_args$args适用于除/之外的所有情况,这会导致404。
我当然可以修改脚本来处理额外的/但它感觉有点肮脏。
我一直在努力寻找和阅读手册,但我不能弄明白,任何指针?
您评论说您的snippets/fastcgi-php.conf包含:
fastcgi_split_path_info ^(.+\.php)(/.+)$;
你会注意到,它与URI /index.php/不匹配,这就解释了为什么你会得到404响应。
您可以通过将正确的语句放在后面(假定您不想编辑系统文件)来覆盖snippets/fastcgi-php.conf的值。 例如:
location / { try_files $uri /index.php$uri$is_args$args; } location /index.php { include snippets/fastcgi-php.conf; include fastcgi_params; fastcgi_split_path_info ^(.+\.php)(/.*)$; fastcgi_pass unix:/var/run/php5-fpm.sock; }
简单地把+改成a *这样在没有其他东西跟在后面的时候就可以匹配。