ec2-webapp icon indicating copy to clipboard operation
ec2-webapp copied to clipboard

nginx should handle HTTP 403 to the backend, too

Open franzenzenhofer opened this issue 14 years ago • 3 comments

/etc/nginx/sites-available/myapp-httpp

currently is:

location / {
root        /var/myapp/public;
index       index.html;
error_page  404 = @backend;
}

should:

location / {
root        /var/myapp/public;
index       index.html;
error_page  404 = @backend;
error_page  403 = @backend;
}

otherwise it is not possible return something from node.js on the root (i.e.: http://www.myapp.com/) of the domain, as nginx (if the 'public' folder exists) needs to handle an HTTP 403 instead of an HTTP 404.

franzenzenhofer avatar Apr 03 '11 19:04 franzenzenhofer

Does this allow an /index.html to be served if there's one? That is, both of the following use-cases are true/successful:

Use-case 1:

  1. There's no index.html in the public (web root) directory
  2. A request for "/" asks @backend to handle the request

Use-case 2:

  1. There is a index.html in the public (web root) directory
  2. A request for "/" returns the index.html (from the public (web root) directory)

AFAIK "redirecting" 403 to the backend would break serving of /index.html, but I haven't confirmed this.

rsms avatar Apr 03 '11 19:04 rsms

with the error_page 403 = @backend; fix

use case 1: if there is no index.html a request for / will be handled to the @backend use case 2: if there is a index.html a request for / will return the index.html in the public folder.

so this fix should fullfill both use cases.

franzenzenhofer avatar Apr 03 '11 20:04 franzenzenhofer

I still get a 502 Bad Gateway error with this fix. What am I doing wrong? I'm running socket.io and expressjs, FYI. Thanks for your time, this is starting to drive me insane.

atestu avatar Aug 11 '11 19:08 atestu