httpd icon indicating copy to clipboard operation
httpd copied to clipboard

FastCGI redirect loop with uWSGI since 6.1

Open hrkfdn opened this issue 8 years ago • 6 comments

Hey,

I just upgraded my system to OpenBSD 6.1 and have been running into problems with my Flask application deployed via uWSGI and FastCGI sockets.

Whenever I try to request the application I end up with a recursive redirect loop:

--2017-05-06 11:40:04--  http://foo.bar/
Resolving foo.bar (foo.bar)... x.x.x.x
Connecting to foo.bar (foo.bar)|x.x.x.x|:80... connected.
HTTP request sent, awaiting response...
  HTTP/1.1 301 Moved Permanently
  Connection: keep-alive
  Content-Type: text/html; charset=utf-8
  Date: Sat, 06 May 2017 09:40:04 GMT
  Location: http://foo.bar/
  Server: OpenBSD httpd
  Transfer-Encoding: chunked
Location: http://foo.bar/ [following]

As you can see I request the root path and get redirected to it. If I run uWSGI in HTTP mode without httpd in between, this does not happen, so I'm assuming it's not a webapp or uWSGI problem. Additionally, this worked fine in 6.0.

Has something changed in the way paths are passed to FastCGI changed between 6.0 and 6.1?

hrkfdn avatar May 06 '17 09:05 hrkfdn

Did some research: This happens, because PATH_INFO is "" when an application mounted at the root path of a domain is requested.

In that case, it should probably be set to "/", otherwise Flask/Werkzeug will respond with an HTTP 301 to /.

Because PATH_INFO is still passed as "" after the redirect, although "/" was requested, an endless redirect loop occurs.

I am unsure, if this is an httpd or Werkzeug error.

hrkfdn avatar Jan 16 '18 00:01 hrkfdn

Faced same problem with httpd--fastcgi--uwsgi(flask). Django survives it somehow, but not Flask. app.url_map.strict_slashes = False fixes issue for Flask.

Since browser explictily sends "/", should not httpd(8) set PATH_INFO="/" for fastcgi? From the other hand, app is mounted to "/", so slash could be treated as mountpoint, not relative path.

throwable-one avatar Jun 02 '18 23:06 throwable-one

I would opt for the first option as it seems to fix many problems and not cause any. But that's just me. I tried convincing many of the parties involved (Flask/Werkzeug, httpd), but unfortunately interest is limited. For now, I just keep my local installation patched.

hrkfdn avatar Jun 04 '18 18:06 hrkfdn

hello, thanks alot! i had the exact same problem, app.url_map.strict_slashes = False solved

flipchan avatar Aug 13 '18 13:08 flipchan

Thanks in advance for opening this issue and providing solution for Flask

artsi0m avatar May 22 '23 09:05 artsi0m