简体   繁体   English

nginx别名反映在PHP_SELF(fpm)中

[英]nginx alias to reflect in PHP_SELF (fpm)

I'm having a file structure like this: 我有一个像这样的文件结构:

nginx default root: nginx默认根目录:

~/marketplace/

attempting to create an alias to: 尝试创建别名以:

~/marketplace/endpoints/sdk/tag.php

under URI location /tagframe.htm 在URI位置/tagframe.htm下

Basically, when I go to http://marketplace/tagframe.htm?t=1&c=2 I need to route the request to ~/marketplace/endpoints/sdk/tag.php with the $query_string preserved 基本上,当我转到http://marketplace/tagframe.htm?t = 1&c = 2时,我需要将请求路由到保留了$ query_string的〜/ marketplace / endpoints / sdk / tag.php

While this works: 尽管这可行:

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

It populates PHP_SELF with the actual path of the file (tag.php), and not URI part (tagframe.htm) which is what I need - for it to think that /tagframe.htm is a real file and populate it into PHP_SELF. 它使用文件的实际路径(tag.php)填充PHP_SELF,而不是我需要的URI部分(tagframe.htm)-认为/tagframe.htm是真实文件,并将其填充到PHP_SELF中。

For example Lighttpd does it through its 例如Lighttpd通过它的

alias.url /tagframe.htm => ~/marketplace/endpoints/sdk/tag.php

And PHP_SELF shows me /tagframe.htm PHP_SELF向我显示了/tagframe.htm

An attempt to trick it was: 试图欺骗它的方法是:

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

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

    include php-fpm;
}

PS $root_path is my map default value of project root (hacky), php-fpm file is default fast_cgi proxy to php: PS $ 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;
}

Any ideas what am I doing wrong? 有什么想法我做错了吗?

You're misusing PHP_SELF. 您正在滥用PHP_SELF。 It's intended to show the actual script file name that is running, not the URL. 它旨在显示正在运行的实际脚本文件名 ,而不是URL。

What you seem to be looking for is REQUEST_URI, ie: 您似乎在寻找的是REQUEST_URI,即:

$_SERVER["REQUEST_URI"]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM