【问题标题】:nginx alias to reflect in PHP_SELF (fpm)反映在 PHP_SELF (fpm) 中的 nginx 别名
【发布时间】:2017-12-07 15:05:48
【问题描述】:

我的文件结构是这样的:

nginx 默认根目录:

~/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 文件是默认的fast_cgi 代理到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;
}

任何想法我做错了什么?

【问题讨论】:

    标签: nginx php lighttpd mod-alias


    【解决方案1】:

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

    您似乎正在寻找的是 REQUEST_URI,即:

    $_SERVER["REQUEST_URI"]
    

    【讨论】:

    • 您想解释一下该变量在上面的配置文件中的位置吗?目前不知道如何处理它。
    猜你喜欢
    • 2020-03-10
    • 2017-05-04
    • 2015-09-14
    • 1970-01-01
    • 1970-01-01
    • 2020-08-08
    • 1970-01-01
    • 1970-01-01
    • 2013-09-28
    相关资源
    最近更新 更多