# Nginx URL Fallback setup with internal redirection in reverse-proxy settings

**URL:** <https://www.ruby-forum.com/t/nginx-url-fallback-setup-with-internal-redirection-in-reverse-proxy-settings/242384>\
**Category:** NGINX\
**Created:** [June 19, 2015, 7:29pm UTC](https://www.ruby-forum.com/t/nginx-url-fallback-setup-with-internal-redirection-in-reverse-proxy-settings/242384 "2015-06-19T19:29:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Detlef\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@Detlef\_R](https://www.ruby-forum.com/u/Detlef_R)\
**Post date:** [June 19, 2015, 7:29pm UTC](https://www.ruby-forum.com/t/nginx-url-fallback-setup-with-internal-redirection-in-reverse-proxy-settings/242384/1 "2015-06-19T19:29:27Z")

</div>

Hi  
List Members Gurus

```
                      I have installed and configured a virtual

```

host using NGINX in Ubuntu 14.04 Now I want to add couple of  
functionalities like–

Set up Nginx config so that any URL address which is not found, goes  
to a fallback path with internal redirection (NO change or redirection  
in browser URL).

Assuming the following:  
Fallback path needed for configuration:  
[http://myvirtualhost/fallback\_directory/fallbackhandler.php](http://myvirtualhost/fallback_directory/fallbackhandler.php)  
Anything typed after [http://localhost](http://localhost) when not found, should hit the  
fallback path (internal redirection, meaning NO change or redirection  
in browser address bar). The  
fallback path is given above  
(http://app\_servers/fallback\_directory/fallbackhandler.php) which  
needs to be setup in Nginx config.

For example, when i visits [www.test.com/not\_existing\_directory/](http://www.test.com/not_existing_directory/) and  
not\_existing\_directory doesn’t exist, it should hit the fallback path  
while still retaining [www.test.com/not\_existing\_directory/](http://www.test.com/not_existing_directory/) in browser  
address bar.

Please point me to NGINX resources and a steps that will be required  
so that I can grasp NGINX quickly to do the above task.

Thanks in advance  
Ashish

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 19, 2015, 9:53pm UTC](https://www.ruby-forum.com/t/nginx-url-fallback-setup-with-internal-redirection-in-reverse-proxy-settings/242384/2 "2015-06-19T21:53:44Z")

</div>

On Fri, Jun 19, 2015 at 10:59:00PM +0530, Ashish k wrote:

Hi there,

> Set up Nginx config so that any URL address which is not found, goes  
> to a fallback path with internal redirection (NO change or redirection  
> in browser URL).

> Please point me to NGINX resources and a steps that will be required  
> so that I can grasp NGINX quickly to do the above task.

It sounds like you want your own handler for 404 errors. So

error\_page 404 @404;

or

error\_page 404 = @404;

[Module ngx\_http\_core\_module](http://nginx.org/r/error_page) for details. and the difference between  
the two lines.

Then in “location @404 {}”, do what you want - proxy\_pass or  
fastcgi\_pass  
to something external with appropriate other settings, most likely.

Good luck with it,

## f

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