# Incorrect $request\_filename in 1.0.5?

**URL:** <https://www.ruby-forum.com/t/incorrect-request-filename-in-1-0-5/211174>\
**Category:** NGINX\
**Created:** [August 28, 2011, 1:22am UTC](https://www.ruby-forum.com/t/incorrect-request-filename-in-1-0-5/211174 "2011-08-28T01:22:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [August 28, 2011, 1:22am UTC](https://www.ruby-forum.com/t/incorrect-request-filename-in-1-0-5/211174/1 "2011-08-28T01:22:47Z")

</div>

Hi, I’ve recently compiled nginx 1.0.5 on localhost (debian), and have  
set up a test site so that i may access it [http://testsite](http://testsite) in the  
browser (set “testsite” to 127.0.0.1 in /etc/hosts and an nginx server  
config with root /var/www/testsite;)

i’ve been having some problems with some rewrites, and started pushing  
some of nginx vars out to php as fastcgi\_param’s to troubleshoot. i’ve  
noticed that $request\_filename is incorrect. it’s showing as  
“/var/www/testsiteindex.php” when accessing [http://testsite/foo/bar/](http://testsite/foo/bar/)  
(which is being redirected to index.php?q=foo/bar/).

i’m not sure if it’s my set up as I’m fairly new at this!

Thanks

Posted at Nginx Forum:

> **[Incorrect $request\_filename in 1.0.5?](https://forum.nginx.org/read.php?2,214376,214376#msg-214376)**
>
> Hi, I've recently compiled nginx 1.0.5 on localhost (debian), and have set up a test site so that i may access it http://testsite in the browser (set "testsite" to 127.0.0.1 in /etc/hosts and an nginx server config with root...

---

<div class="post-metadata">

**Author:** ![Roger\_Smith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/4af34b/32.png) [@Roger\_Smith](https://www.ruby-forum.com/u/Roger_Smith)\
**Post date:** [August 28, 2011, 8:27am UTC](https://www.ruby-forum.com/t/incorrect-request-filename-in-1-0-5/211174/2 "2011-08-28T08:27:35Z")

</div>

$request\_filename will change when you rewrite the request, even if you  
just do an internal rewrite.  
$request\_filename is defined as root or alias directive + current URI.

So if you have a root defined as /var/www/testsite and you redirect to  
index.php then you’ll get /var/www/testsiteindex.php

URIs in Nginx always start with a / so it’s generally a good idea to  
rewrite to /index.php instead of index.php

Posted at Nginx Forum:

> **[Re: Incorrect $request\_filename in 1.0.5?](https://forum.nginx.org/read.php?2,214376,214378#msg-214378)**
>
> Hi, I've recently compiled nginx 1.0.5 on localhost (debian), and have set up a test site so that i may access it http://testsite in the browser (set "testsite" to 127.0.0.1 in /etc/hosts and an nginx server config with root...

---

<div class="post-metadata">

**Author:** ![Roger\_Smith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/4af34b/32.png) [@Roger\_Smith](https://www.ruby-forum.com/u/Roger_Smith)\
**Post date:** [August 28, 2011, 4:19pm UTC](https://www.ruby-forum.com/t/incorrect-request-filename-in-1-0-5/211174/3 "2011-08-28T16:19:39Z")

</div>

Hi, thanks for the reply. Ok, so I’ve changed to /index.php, but  
$\_SERVER[‘SCRIPT\_FILENAME’] is now /var/www/testsite//index.php (double  
slash before index.php)

while the nginx $request\_filename is correct. Surely that isn’t right?

Posted at Nginx Forum:

> **[Re: Incorrect $request\_filename in 1.0.5?](https://forum.nginx.org/read.php?2,214376,214388#msg-214388)**
>
> Hi, I've recently compiled nginx 1.0.5 on localhost (debian), and have set up a test site so that i may access it http://testsite in the browser (set "testsite" to 127.0.0.1 in /etc/hosts and an nginx server config with root...

---

<div class="post-metadata">

**Author:** ![Roger\_Smith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/4af34b/32.png) [@Roger\_Smith](https://www.ruby-forum.com/u/Roger_Smith)\
**Post date:** [August 28, 2011, 9:18pm UTC](https://www.ruby-forum.com/t/incorrect-request-filename-in-1-0-5/211174/4 "2011-08-28T21:18:22Z")

</div>

Full points to you Sir! Thanks!

Posted at Nginx Forum:

> **[Re: Incorrect $request\_filename in 1.0.5?](https://forum.nginx.org/read.php?2,214376,214399#msg-214399)**
>
> Hi, I've recently compiled nginx 1.0.5 on localhost (debian), and have set up a test site so that i may access it http://testsite in the browser (set "testsite" to 127.0.0.1 in /etc/hosts and an nginx server config with root...

---

<div class="post-metadata">

**Author:** ![Roger\_Smith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/4af34b/32.png) [@Roger\_Smith](https://www.ruby-forum.com/u/Roger_Smith)\
**Post date:** [August 28, 2011, 7:48pm UTC](https://www.ruby-forum.com/t/incorrect-request-filename-in-1-0-5/211174/5 "2011-08-28T19:48:52Z")

</div>

On Sun, Aug 28, 2011 at 10:18:51AM -0400, Roger Smith wrote:

> Hi, thanks for the reply. Ok, so I’ve changed to /index.php, but  
> $\_SERVER[‘SCRIPT\_FILENAME’] is now /var/www/testsite//index.php (double  
> slash before index.php)
> 
> while the nginx $request\_filename is correct. Surely that isn’t right?

You probably have the directive

```
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;

```

It should be changed to

```
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

```

–  
Igor S.
