1

This used to work:

server {
  server_name example.com;

  location / {
    proxy_pass http://localhost:8888;
    error_page 502 /502.html;
  }

  location = /502.html {
    root /var/www/example;
  }
}

Now suddenly it doesn't anymore... I don't know what changed ?

I get 404 instead of displayed /var/www/example/index.html in case port 8888 doesn't respond...

How to make this work again? thank you

davidhq
  • 215
  • 2
  • 9

2 Answers2

0

Your configuration states that the error document is /var/www/example/502.html. Nothing in your configuration attempts to load /var/www/example/index.html at any time, ever. Rename the file.

Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
  • First: I assure you this exact configuration worked some time ago (it somehow served index.html from that dir correctly although it's not specified), I agree it's strange.. but I have also tried to copy `index.html` into `502.html` and then the page displays but all resources (img, css) are not visible, because there is 502 on them... see `bitcells.com` please.. this is now serving 502.html and images are missing... so what would be the complete code to make this work? thank you – davidhq Apr 22 '16 at 08:32
  • http://cl.ly/3N1r0J1a1O0b – davidhq Apr 22 '16 at 09:12
0

The majority of your content lives on the remote server. You need to serve an error page (together with some resources) locally. You need a "special location" which is distinct from any location served from upstream, and put all of your local resources in there. I can't pick a name for that location, as I have no idea what you are serving from 8888. But lets say /error_pages for now.

server {
    server_name example.com;

    location / {
        proxy_pass http://localhost:8888;
        error_page 502 /error_pages/502.html;
    }

    location /error_pages {
        root /var/www/example;
    }
}

With the above configuration, you will need to edit 502.html and change the URLs of the resources to add the /error_pages prefix.

You will also need to move all of the files (502.html and its resource files) into /var/www/example/error_pages/ subdirectory.

Richard Smith
  • 11,859
  • 2
  • 18
  • 26
  • Thank you, but is there no way to serve something that is actually not an error page? Imagine I want to serve something from my local machine via SSH forwarding on port 8888.. but when this is not active, I just want to show regular page (so semantically this is not an error page)... can I somehow reuse the normal page like `index.html` without changing any of its resources? Exactly this magically worked before now I really don't know why or how anymore and I didn't change my configuration, just doesn't work as it used to... – davidhq Apr 22 '16 at 09:11
  • ok maybe it is not possible... I did as you said, and I have it working but with duplication of resources inside `error_pages` folder... I don't really like it but I guess I'll have to – davidhq Apr 24 '16 at 20:55