# Nginx rewrite help

**URL:** <https://www.ruby-forum.com/t/nginx-rewrite-help/170499>\
**Category:** NGINX\
**Created:** [June 18, 2009, 6:31am UTC](https://www.ruby-forum.com/t/nginx-rewrite-help/170499 "2009-06-18T06:31:04Z")\
**Posts on this page:** 11\
**Page:** 2

<div class="post-metadata">

**Author:** ![Kevin\_Castiglione](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecd19e/32.png) [@Kevin\_Castiglione](https://www.ruby-forum.com/u/Kevin_Castiglione)\
**Post date:** [June 19, 2009, 8:19am UTC](https://www.ruby-forum.com/t/nginx-rewrite-help/170499/21 "2009-06-19T08:19:03Z")

</div>

On Fri, Jun 19, 2009 at 12:18 PM, Kevin  
Castiglione[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> This also produces the same result. the mapping does not work as expected.  
> thank you!

you may want to check which variables used by your program and adjust  
them accordingly.

For example, in (at least) php these are the variables related to  
document path

SCRIPT\_FILENAME  
SCRIPT\_NAME  
REQUEST\_URI  
DOCUMENT\_URI  
DOCUMENT\_ROOT

You may need to adjust one or more of these variables (or maybe other  
variables) to make your program works

---

<div class="post-metadata">

**Author:** ![Kevin\_Castiglione](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecd19e/32.png) [@Kevin\_Castiglione](https://www.ruby-forum.com/u/Kevin_Castiglione)\
**Post date:** [June 19, 2009, 3:02pm UTC](https://www.ruby-forum.com/t/nginx-rewrite-help/170499/22 "2009-06-19T15:02:05Z")

</div>

On Thu, Jun 18, 2009 at 11:06 PM, Edho P Arief [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> /$host$fastcgi\_script\_name;
> 
> variables) to make your program works

i tried all of these and still no result. my web app is written in  
python  
and uses flup fastcgi middleware.  
thank you!

---

<div class="post-metadata">

**Author:** ![Kevin\_Castiglione](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecd19e/32.png) [@Kevin\_Castiglione](https://www.ruby-forum.com/u/Kevin_Castiglione)\
**Post date:** [June 19, 2009, 8:25am UTC](https://www.ruby-forum.com/t/nginx-rewrite-help/170499/23 "2009-06-19T08:25:31Z")

</div>

On Thu, Jun 18, 2009 at 05:26:02PM -0700, Kevin Castiglione wrote:

> > > > > > On Thu, Jun 18, 2009 at 07:21:33AM -0700, Kevin Castiglione wrote:
> > > > > > 
> > > > > > > > > > >
> > 
> > url to
> > 
> > > > > > > > If you use proxing, then
> > > > > 
> > > > > does this mean the backend fastcgi processes have to be in the same
> 
> while this is what i want on the webapp/fastcgi backend  
> worker\_connections 1024;
> 
> ```
> server app1.XXX.com:8492 fail_timeout=1s;
> location / {
> fastcgi_param REMOTE_ADDR $remote_addr;
> fastcgi_param REMOTE_PORT $remote_port;
> fastcgi_param SERVER_PROTOCOL $server_protocol;
> fastcgi_param SERVER_ADDR $server_addr;
> fastcgi_param SERVER_PORT $server_port;
> fastcgi_param SERVER_NAME $server_name;
> 
> }
> 
> }
> 
> ```
> 
> }

Probably, you need

fastcgi\_param SCRIPT\_FILENAME  
/home/app/work/flock/$host$fastcgi\_script\_name;

or

fastcgi\_param SCRIPT\_FILENAME $document\_root/$host$fastcgi\_script\_name;

---

<div class="post-metadata">

**Author:** ![Kevin\_Castiglione](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecd19e/32.png) [@Kevin\_Castiglione](https://www.ruby-forum.com/u/Kevin_Castiglione)\
**Post date:** [June 20, 2009, 9:38am UTC](https://www.ruby-forum.com/t/nginx-rewrite-help/170499/24 "2009-06-20T09:38:54Z")

</div>

2009/6/19 Igor S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> $document\_root/$host$fastcgi\_script\_name;
> 
> > > 
> > 
> > tried these with no results igor!
> 
> What server did you use before nginx ?

ive always used nginx. this is a new setup im trying to do.  
thank you

---

<div class="post-metadata">

**Author:** ![Kevin\_Castiglione](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecd19e/32.png) [@Kevin\_Castiglione](https://www.ruby-forum.com/u/Kevin_Castiglione)\
**Post date:** [June 20, 2009, 9:59am UTC](https://www.ruby-forum.com/t/nginx-rewrite-help/170499/25 "2009-06-20T09:59:22Z")

</div>

On Fri, Jun 19, 2009 at 07:28:39AM -0700, Kevin Castiglione wrote:

> > > > fastcgi\_param SCRIPT\_FILENAME  
> > > > $document\_root/$host$fastcgi\_script\_name;
> > > 
> > > > 
> > > 
> > > tried these with no results igor!
> > 
> > What server did you use before nginx ?
> 
> ive always used nginx. this is a new setup im trying to do.

What do you use as FastCGI backend ?

---

<div class="post-metadata">

**Author:** ![Kevin\_Castiglione](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecd19e/32.png) [@Kevin\_Castiglione](https://www.ruby-forum.com/u/Kevin_Castiglione)\
**Post date:** [June 20, 2009, 9:59am UTC](https://www.ruby-forum.com/t/nginx-rewrite-help/170499/26 "2009-06-20T09:59:23Z")

</div>

On Fri, Jun 19, 2009 at 9:28 PM, Kevin  
Castiglione[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > >

how’s the old setup looks like?

---

<div class="post-metadata">

**Author:** ![Kevin\_Castiglione](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecd19e/32.png) [@Kevin\_Castiglione](https://www.ruby-forum.com/u/Kevin_Castiglione)\
**Post date:** [June 20, 2009, 10:05am UTC](https://www.ruby-forum.com/t/nginx-rewrite-help/170499/27 "2009-06-20T10:05:14Z")

</div>

2009/6/19 Igor S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> > > > >
> 
> What do you use as FastCGI backend ?

python flup is the fastcgi middleware and web.py is the web framework

---

<div class="post-metadata">

**Author:** ![Kevin\_Castiglione](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecd19e/32.png) [@Kevin\_Castiglione](https://www.ruby-forum.com/u/Kevin_Castiglione)\
**Post date:** [June 20, 2009, 8:11am UTC](https://www.ruby-forum.com/t/nginx-rewrite-help/170499/28 "2009-06-20T08:11:46Z")

</div>

On Fri, Jun 19, 2009 at 05:54:06AM -0700, Kevin Castiglione wrote:

> > Probably, you need
> > 
> > fastcgi\_param SCRIPT\_FILENAME  
> > /home/app/work/flock/$host$fastcgi\_script\_name;
> > 
> > or
> > 
> > fastcgi\_param SCRIPT\_FILENAME $document\_root/$host$fastcgi\_script\_name;
> 
> tried these with no results igor!

What server did you use before nginx ?

---

<div class="post-metadata">

**Author:** ![Kevin\_Castiglione](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecd19e/32.png) [@Kevin\_Castiglione](https://www.ruby-forum.com/u/Kevin_Castiglione)\
**Post date:** [June 20, 2009, 10:09am UTC](https://www.ruby-forum.com/t/nginx-rewrite-help/170499/29 "2009-06-20T10:09:55Z")

</div>

On Fri, Jun 19, 2009 at 7:48 AM, Edho P Arief [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > > > >
> > 
> > thank you
> 
> how’s the old setup looks like?

the config for the current setup is given below. i have different  
domains  
setup with different server blocks. i want to combine them to one  
fastcgi  
backend, and my webframe work supports only url level - sub application  
processing. hence i need the url mapping.  
thank you!

#user nobody;  
worker\_processes 1;

error\_log /home/app/error\_all.log;  
pid /home/app/nginx.pid;

events {  
worker\_connections 1024;  
}

http {  
include mime.types;  
default\_type application/octet-stream;  
client\_header\_buffer\_size 8k;  
large\_client\_header\_buffers 4 8k;  
fastcgi\_buffers 32 4k;  
fastcgi\_buffer\_size 4k;  
sendfile on;

```
server_names_hash_bucket_size 64;
keepalive_timeout 5;

gzip on;
gzip_comp_level 1;
gzip_proxied private;
gzip_buffers 8 4k;

upstream backend_flock{
    server app1.XXX.com:8492 fail_timeout=1s;
}
server {
    listen 8080;
    access_log /home/app/access_flock.log;

    client_max_body_size 10m;

    location /static {
        root /home/app/work/flock;
    }
    location / {
        root /home/app/work/flock;

        fastcgi_pass backend_flock;

        fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_script_name;
        fastcgi_param QUERY_STRING $query_string;
        fastcgi_param CONTENT_TYPE $content_type;
        fastcgi_param CONTENT_LENGTH $content_length;
        fastcgi_param REQUEST_METHOD $request_method;
        fastcgi_param REMOTE_ADDR $remote_addr;
        fastcgi_param REMOTE_PORT $remote_port;
        fastcgi_param SERVER_PROTOCOL $server_protocol;
        fastcgi_param SERVER_ADDR $server_addr;
        fastcgi_param SERVER_PORT $server_port;
        fastcgi_param SERVER_NAME $server_name;

    }

}

```

}

---

<div class="post-metadata">

**Author:** ![Kevin\_Castiglione](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecd19e/32.png) [@Kevin\_Castiglione](https://www.ruby-forum.com/u/Kevin_Castiglione)\
**Post date:** [June 20, 2009, 10:28am UTC](https://www.ruby-forum.com/t/nginx-rewrite-help/170499/30 "2009-06-20T10:28:37Z")

</div>

On Fri, Jun 19, 2009 at 07:59:55AM -0700, Kevin Castiglione wrote:

> > > > > > fastcgi\_param SCRIPT\_FILENAME
> 
> backend, and my webframe work supports only url level - sub application  
> processing. hence i need the url mapping.

So now you use differen ports in upstream, say, 8492:

```
     server app1.XXX.com:8492 fail_timeout=1s;

```

Yes ?

With this configuraiton

```
         fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
         fastcgi_param PATH_INFO $fastcgi_script_name;

```

both SCRIPT\_FILENAME and PATH\_INFO are equal to URI, i.e., if client  
requests “/some/page”, then these parameter will be “/some/page” too.

Probably, you need

```
         fastcgi_param SCRIPT_FILENAME /$host$fastcgi_script_name;
         fastcgi_param PATH_INFO /$host$fastcgi_script_name;

```

Then, if client requests “[porkbun.com | parked domain](http://abc.de.com/some/page)”, then these  
parameters will be “[//abc.de.com/some/page](https://abc.de.com/some/page)”. You may see it in debug  
log.

---

<div class="post-metadata">

**Author:** ![Kevin\_Castiglione](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecd19e/32.png) [@Kevin\_Castiglione](https://www.ruby-forum.com/u/Kevin_Castiglione)\
**Post date:** [June 20, 2009, 11:41am UTC](https://www.ruby-forum.com/t/nginx-rewrite-help/170499/31 "2009-06-20T11:41:51Z")

</div>

2009/6/19 Igor S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> > > > > > tried these with no results igor!
> > 
> > the config for the current setup is given below. i have different domains  
> > setup with different server blocks. i want to combine them to one fastcgi  
> > backend, and my webframe work supports only url level - sub application  
> > processing. hence i need the url mapping.
> 
> So now you use differen ports in upstream, say, 8492:
> 
> ```
> server app1.XXX.com:8492 <http://app1.xxx.com:8492/>fail_timeout=1s;
> 
> ```
> 
> Yes ?

yes, differentports

> ```
> fastcgi_param SCRIPT_FILENAME /$host$fastcgi_script_name;
> fastcgi_param PATH_INFO /$host$fastcgi_script_name;
> 
> ```
> 
> finally got it working  
> these are the changes i had to do

```
        fastcgi_param SCRIPT_NAME $host$fastcgi_script_name;
        fastcgi_param SCRIPT_FILENAME /$host$fastcgi_script_name;
        fastcgi_param PATH_INFO /$host$fastcgi_script_name;

```

thanks a lot igor and edho!

[Previous page](https://www.ruby-forum.com/t/nginx-rewrite-help/170499.md?page=1)
