简体   繁体   中英

nginx alias to reflect in PHP_SELF (fpm)

I'm having a file structure like this:

nginx default root:

~/marketplace/

attempting to create an alias to:

~/marketplace/endpoints/sdk/tag.php

under URI location /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

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.

For example Lighttpd does it through its

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

And PHP_SELF shows me /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:

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. It's intended to show the actual script file name that is running, not the URL.

What you seem to be looking for is REQUEST_URI, ie:

$_SERVER["REQUEST_URI"]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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