Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a node web app with nginx acting as a proxy.

Here's the server block for that site :

server {
        listen 80;


        location / {
                # Offline handling

                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
                proxy_set_header X-NginX-Proxy true;

                proxy_redirect off;

                # Support
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";

If the web app ever goes down, then the error_page directive sends the user off-site, but the url ends up changing. Is it possible to send the user to that site, but maintain the same url in the browser?

share|improve this question

As the doc says :

If there is no need to change URI during internal redirection it is possible to pass error processing into a named location:

location / {
    error_page 404 = @fallback; }

location @fallback { 
    proxy_pass http://backend;

You would also need to put on the proxy_intercept_errors directive.

Also, to respect the URL format you give in your example (, i had to use a $folder variable.

Finally, you will have to setup the resolver directive.

To conclude, you will have something like this :

location / {
   proxy_intercept_errors on;
   error_page 404 = @fallback;

location @fallback {
   resolver;   # <-- Put your own DNS Server here
   set $folder "502";
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.