# Problem with $\_SERVER;

**URL:** <https://www.ruby-forum.com/t/problem-with-server/207898>\
**Category:** NGINX\
**Created:** [June 5, 2011, 10:23pm UTC](https://www.ruby-forum.com/t/problem-with-server/207898 "2011-06-05T22:23:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [June 5, 2011, 10:23pm UTC](https://www.ruby-forum.com/t/problem-with-server/207898/1 "2011-06-05T22:23:14Z")

</div>

In my nginx server, $\_SERVER[‘REQUEST\_URI’]; does not work, and returns  
nothing. When using getenv(“REQUEST\_URI”); it will returns the url of  
the current page instead of the reffering url. And in this case, it will  
return the current filename (e.g. /test.php) not the full url. I have  
tested this on apache, and there is no problem; thus it is something  
related to nginx setting. Any idea?

Posted at Nginx Forum:

> **[Problem with $\_SERVER\['REQUEST\_URI'\];](https://forum.nginx.org/read.php?2,204171,204171#msg-204171)**
>
> In my nginx server, $\_SERVER\['REQUEST\_URI'\]; does not work, and returns nothing. When using getenv("REQUEST\_URI"); it will returns the url of the current page instead of the reffering url. And in this case, it will return the current...

---

<div class="post-metadata">

**Author:** ![etrader](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b5e925/32.png) [@etrader](https://www.ruby-forum.com/u/etrader)\
**Post date:** [June 5, 2011, 11:29pm UTC](https://www.ruby-forum.com/t/problem-with-server/207898/2 "2011-06-05T23:29:36Z")

</div>

Hello!

On Sun, Jun 05, 2011 at 04:22:40PM -0400, etrader wrote:

> In my nginx server, $\_SERVER[‘REQUEST\_URI’]; does not work, and returns  
> nothing. When using getenv(“REQUEST\_URI”); it will returns the url of  
> the current page instead of the reffering url. And in this case, it will  
> return the current filename (e.g. /test.php) not the full url. I have

REQUEST\_URI is expected to contain URI used to access the page in  
question. I.e. it’s expected to contain ‘/test.php’ if you access  
‘/test.php’ URI. Note that HTTP historically uses only absolute  
path on an origin server as URI, not the absolute URL.

Reffering url may (or may not) be present in Referer header, which  
should be available in php as HTTP\_REFERER.

> tested this on apache, and there is no problem; thus it is something  
> related to nginx setting. Any idea?

nginx doesn’t execute php scripts by itself, it only passes  
requests to backend you configured (via one of the supported  
protocols, that is http, fastcgi, …).

As you see getenv(“REQUEST\_URI”) but not $\_SERVER[‘REQUEST\_URI’] -  
it looks like data is available on your backend, but for some  
reason only via getenv(), not $\_SERVER. Check your php backend  
to find out why this happens.

Maxim D.

---

<div class="post-metadata">

**Author:** ![etrader](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/b5e925/32.png) [@etrader](https://www.ruby-forum.com/u/etrader)\
**Post date:** [June 6, 2011, 12:45am UTC](https://www.ruby-forum.com/t/problem-with-server/207898/3 "2011-06-06T00:45:31Z")

</div>

Thanks for your informative description. The code is inside 404.php as I  
want to get the requested page which led to error page. For example,  
when accessing test.html which does not exist, I want to echo  
“test.html” by php code of 404.php

Posted at Nginx Forum:

> **[Re: Problem with $\_SERVER\['REQUEST\_URI'\];](https://forum.nginx.org/read.php?2,204171,204203#msg-204203)**
>
> In my nginx server, $\_SERVER\['REQUEST\_URI'\]; does not work, and returns nothing. When using getenv("REQUEST\_URI"); it will returns the url of the current page instead of the reffering url. And in this case, it will return the current...
