nginx别名以PHP_SELF(fpm)反映

时间:2017-12-07 15:05:48

标签: nginx php lighttpd mod-alias

我的文件结构如下:

nginx默认root:

~/marketplace/

尝试创建别名:

~/marketplace/endpoints/sdk/tag.php

在URI位置/tagframe.htm

基本上,当我转到http://marketplace/tagframe.htm?t=1&c=2时,我需要将请求路由到〜/ marketplace / endpoints / sdk / tag.php并保留$ query_string

虽然这有效:

location /tagframe.htm {
    try_files $uri /endpoints/sdk/tag.php$is_args$args;
}

它使用文件的实际路径(tag.php)填充PHP_SELF,而不是我需要的URI部分(tagframe.htm) - 因为它认为/tagframe.htm是一个真实的文件并填充它进入PHP_SELF。

例如Lighttpd通过它的

来完成它
alias.url /tagframe.htm => ~/marketplace/endpoints/sdk/tag.php

PHP_SELF向我显示/tagframe.htm

试图欺骗它是:

location /tagframe.htm {
    alias $root_path/endpoints/sdk;

    rewrite (.*) /endpoints/sdk/tag.php?$query_string;

    include php-fpm;
}

P.S $ root_path是我的地图默认值项目根(hacky),php-fpm文件是php的默认fast_cgi代理:

location ~ \.php$ {
    try_files $uri =404;
    fastcgi_pass unix:/tmp/php5-fpm.sock;
    fastcgi_index index.php;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    fastcgi_param SERVER_NAME $host;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
}

任何想法我做错了什么?

1 个答案:

答案 0 :(得分:0)

你误用了PHP_SELF。它旨在显示正在运行的the actual script file name,而不是URL。

你似乎在寻找的是REQUEST_URI,即:

$_SERVER["REQUEST_URI"]