# Off-domain redirect using X-Accel-Redirect

**URL:** <https://www.ruby-forum.com/t/off-domain-redirect-using-x-accel-redirect/205721>\
**Category:** NGINX\
**Created:** [April 14, 2011, 7:37am UTC](https://www.ruby-forum.com/t/off-domain-redirect-using-x-accel-redirect/205721 "2011-04-14T07:37:11Z")\
**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:** [April 14, 2011, 7:37am UTC](https://www.ruby-forum.com/t/off-domain-redirect-using-x-accel-redirect/205721/1 "2011-04-14T07:37:11Z")

</div>

Hello,

I’d like for my application to send a 302 redirect (or equivalent) to an  
off-domain location (not my server). X-Accel-Redirect appears to be the  
best way to achieve this, but I don’t see any reference to the URI being  
a reference to a different server.

Is something like the following allowed?

X-Accel-Redirect: [http://www.google.com](http://www.google.com);  
or  
X-Accel-Redirect: [http://img.pics.com/mypic.gif](http://img.pics.com/mypic.gif);

I get a 404 from nginx when attempting this. I do not have any  
X-specific header directives (block or pass) in my configuration.

To be clear, I don’t mind debugging it myself, I just want to verify  
that this is possible before I spend too much time on it.

Cheers,

Dean

Posted at Nginx Forum:

> **[off-domain redirect using X-Accel-Redirect](https://forum.nginx.org/read.php?2,191163,191163#msg-191163)**
>
> Hello, I'd like for my application to send a 302 redirect (or equivalent) to an off-domain location (not my server). X-Accel-Redirect appears to be the best way to achieve this, but I don't see any reference to the URI being a reference to a...

---

<div class="post-metadata">

**Author:** ![dbanks](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c68b51/32.png) [@dbanks](https://www.ruby-forum.com/u/dbanks)\
**Post date:** [April 14, 2011, 9:42am UTC](https://www.ruby-forum.com/t/off-domain-redirect-using-x-accel-redirect/205721/2 "2011-04-14T09:42:30Z")

</div>

On Thu, Apr 14, 2011 at 01:36:56AM -0400, dbanks wrote:

Hi there,

> I’d like for my application to send a 302 redirect (or equivalent) to an  
> off-domain location (not my server). X-Accel-Redirect appears to be the  
> best way to achieve this, but I don’t see any reference to the URI being  
> a reference to a different server.

X-Accel-Redirect is for the application to tell nginx to return the  
content of a different (local) uri. The value should start with “/”.

Nginx is a proxy server, so there are ways to map a local uri to a  
remote  
resource, but that seems to be a side issue here:

if you want your application to send a 302 redirect, just send a 302  
redirect. You’ll need a valid Location: header too.

> Is something like the following allowed?
> 
> X-Accel-Redirect: [http://www.google.com](http://www.google.com);  
> or  
> X-Accel-Redirect: [http://img.pics.com/mypic.gif](http://img.pics.com/mypic.gif);

It’s allowed, but it doesn’t do what you hope it does.

If you look in the debug log, you’ll see something like

open() “/usr/local/nginx/htmlhttp://www.google.com;” failed (2: No such  
file or directory)

Good luck with it,

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![dbanks](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c68b51/32.png) [@dbanks](https://www.ruby-forum.com/u/dbanks)\
**Post date:** [April 15, 2011, 1:35am UTC](https://www.ruby-forum.com/t/off-domain-redirect-using-x-accel-redirect/205721/3 "2011-04-15T01:35:42Z")

</div>

Sending a 302 directly works great. Thanks!

Posted at Nginx Forum:

> **[Re: off-domain redirect using X-Accel-Redirect](https://forum.nginx.org/read.php?2,191163,191406#msg-191406)**
>
> Hello, I'd like for my application to send a 302 redirect (or equivalent) to an off-domain location (not my server). X-Accel-Redirect appears to be the best way to achieve this, but I don't see any reference to the URI being a reference to a...

---

<div class="post-metadata">

**Author:** ![dbanks](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c68b51/32.png) [@dbanks](https://www.ruby-forum.com/u/dbanks)\
**Post date:** [April 15, 2011, 2:50am UTC](https://www.ruby-forum.com/t/off-domain-redirect-using-x-accel-redirect/205721/4 "2011-04-15T02:50:20Z")

</div>

it would be nice to support this. it’s basically dynamic/reproxy  
capabilities, which is what is in perlbal, which is needed for  
mogilefs support. I thought nginx had something like this internally,  
or perhaps Valery figured out a neat way in his mogilefs module.
