Nginx。获取完整的请求 uri
Nginx. Get full request uri
是否可以从 Nginx 获取完整的请求 URI?
例如,我想从 URI 中获取 ?
和 #
等字符。
我的示例Nginx配置文件(省略了一些不重要的部分):
server {
listen 80;
server_name test.dev;
root /srv/http/test/public;
index index.php;
try_files $uri $uri/ @rewrite;
location @rewrite {
rewrite ^/(.*)$ /index.php?_url=/;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}
我的index.php:
<?php
echo '<pre>';
print_r($_GET);
echo '</pre>';die;
我用这样的URL来测试http://test.dev/"A / \ \f b ? c.@mail.com
。
实际输出:
Array
(
[_url] => /"A / \ \f b
[c_@mail_com] =>
)
预期输出:
Array
(
[_url] => /"A / \ \f b ? c.@mail.com
)
$request
variable不正是您所需要的吗?
是否可以从 Nginx 获取完整的请求 URI?
例如,我想从 URI 中获取 ?
和 #
等字符。
我的示例Nginx配置文件(省略了一些不重要的部分):
server {
listen 80;
server_name test.dev;
root /srv/http/test/public;
index index.php;
try_files $uri $uri/ @rewrite;
location @rewrite {
rewrite ^/(.*)$ /index.php?_url=/;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}
我的index.php:
<?php
echo '<pre>';
print_r($_GET);
echo '</pre>';die;
我用这样的URL来测试http://test.dev/"A / \ \f b ? c.@mail.com
。
实际输出:
Array
(
[_url] => /"A / \ \f b
[c_@mail_com] =>
)
预期输出:
Array
(
[_url] => /"A / \ \f b ? c.@mail.com
)
$request
variable不正是您所需要的吗?