# How to make a named location in subrequest

**URL:** <https://www.ruby-forum.com/t/how-to-make-a-named-location-in-subrequest/215922>\
**Category:** NGINX\
**Created:** [January 19, 2012, 1:24pm UTC](https://www.ruby-forum.com/t/how-to-make-a-named-location-in-subrequest/215922 "2012-01-19T13:24:57Z")\
**Posts on this page:** 4\
**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:** [January 19, 2012, 1:24pm UTC](https://www.ruby-forum.com/t/how-to-make-a-named-location-in-subrequest/215922/1 "2012-01-19T13:24:57Z")

</div>

Hi,

Previously, I wrote a module to make a subrequest to backend. nginx.conf  
like that:

location /file {  
nphase\_uri /dummy;  
nphase\_set\_uri\_var $np\_uri [http://backend](http://backend);  
}

location /dummy {  
proxy\_pass $np\_uri;  
}

The module could send original URI “[http://localhost/file/abcd.txt](http://localhost/file/abcd.txt)” to  
backend to process.  
And the module could get response from backend and decide to continue or  
refuse.

But now This fix disabled sending original URI to backend.

```
*) Bugfix: a "proxy_pass" directive without URI part might use

```

original  
request after redirection with the “try\_files” directive.

If we need to send same request to backend, we must use named location.  
But it  
seems that named location is not support in subrequest. The named  
location only  
processed in try\_files phase.

Following configuration would not work, for the subrequest send a  
request “GET /dummy”  
rather than original URI.

location /dummy {  
try\_files /dummy @named;  
}  
location @named {  
proxy\_pass $np\_uri;  
}

So how do I make it work?

Posted at Nginx Forum:

> **[how to make a named location in subrequest](https://forum.nginx.org/read.php?2,221447,221447#msg-221447)**
>
> Hi, Previously, I wrote a module to make a subrequest to backend. nginx.conf like that: location /file { nphase\_uri /dummy; nphase\_set\_uri\_var $np\_uri http://backend; } location /dummy { proxy\_pass $np\_uri; }

---

<div class="post-metadata">

**Author:** ![bigplum](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/7c8e57/32.png) [@bigplum](https://www.ruby-forum.com/u/bigplum)\
**Post date:** [January 19, 2012, 5:06pm UTC](https://www.ruby-forum.com/t/how-to-make-a-named-location-in-subrequest/215922/2 "2012-01-19T17:06:59Z")

</div>

Hello!

On Thu, Jan 19, 2012 at 07:24:29AM -0500, bigplum wrote:

> location /dummy {  
> \*) Bugfix: a “proxy\_pass” directive without URI part might use  
> request “GET /dummy”  
> rather than original URI.
> 
> location /dummy {  
> try\_files /dummy @named;  
> }  
> location @named {  
> proxy\_pass $np\_uri;  
> }
> 
> So how do I make it work?

You may explicitly specify URI you want to use in a request to  
backend, i.e.

```
location /dummy {
    proxy_pass $np_uri$request_uri;
}

```

Maxim D.

---

<div class="post-metadata">

**Author:** ![bigplum](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/7c8e57/32.png) [@bigplum](https://www.ruby-forum.com/u/bigplum)\
**Post date:** [January 20, 2012, 9:04am UTC](https://www.ruby-forum.com/t/how-to-make-a-named-location-in-subrequest/215922/3 "2012-01-20T09:04:49Z")

</div>

Thanks to Maxim D…

Finally I modify the module. Cat the URI string to $np\_uri, make $np\_uri  
like that [http://backend/filename.ext](http://backend/filename.ext).

Posted at Nginx Forum:

> **[Re: how to make a named location in subrequest](https://forum.nginx.org/read.php?2,221447,221467#msg-221467)**
>
> Hi, Previously, I wrote a module to make a subrequest to backend. nginx.conf like that: location /file { nphase\_uri /dummy; nphase\_set\_uri\_var $np\_uri http://backend; } location /dummy { proxy\_pass $np\_uri; }

---

<div class="post-metadata">

**Author:** ![bigplum](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/7c8e57/32.png) [@bigplum](https://www.ruby-forum.com/u/bigplum)\
**Post date:** [January 20, 2012, 9:24am UTC](https://www.ruby-forum.com/t/how-to-make-a-named-location-in-subrequest/215922/4 "2012-01-20T09:24:01Z")

</div>

The r-\>unparsed\_uri has been used to cat.

Posted at Nginx Forum:

> **[Re: how to make a named location in subrequest](https://forum.nginx.org/read.php?2,221447,221468#msg-221468)**
>
> Hi, Previously, I wrote a module to make a subrequest to backend. nginx.conf like that: location /file { nphase\_uri /dummy; nphase\_set\_uri\_var $np\_uri http://backend; } location /dummy { proxy\_pass $np\_uri; }
