Reverse proxy backend is unresponsive
I have a revers proxy through Caddy, that is connecting my frontend and backend. It seems to be working fine for my frontend. But is failing on the backend. The backend is a django service.
The proxy is defined by
I am not getting any responses from django. But I am hitting it. I see some network activity. But no response
I put the service in debug mode, but yet, it still is not responding with anything. I am getting 502 errors.
The django service is being ran with
python manage.py runserver 0.0.0.0:${PORT:-8000}
.
Unsure what to do / change to get this running43 Replies
Project ID:
40943c2e-d9a8-4f3c-b414-73ea73eccd8f
40943c2e-d9a8-4f3c-b414-73ea73eccd8f
There are no real logs from django (normally it would respond with what endpoints are hit in debug mode)
Requests to the backend, end up with an error
And frontend requests make it through no problem
My env for the reverse proxy:
runserver
starts a development server, even if you are only testing you still dont want to be using it on Railway, instead use gunicorn like this gunicorn mysite.wsgi -b [::]:$PORT
(replacing mysite
with the name of the folder that contains wsgi.py)I was originally doing
gunicorn BBWare.wsgi -b [::]:${PORT:-8000}
but was still getting the same issue. But yea, let me try with that but debug still on (I have my deployment select between the two based on if debug is on)little context, the private network is ipv6 only so your app would need to listen on ipv6
For the run server, yea, I guess it wouldn't be. But the gunicorn should be correct for doing that? Unless there is an extra setting I need to change in the django settings?
what you have should have worked, maybe you are overwriting the start command somewhere else
Also, can confirm, just having the gunicorn config file in existence does make it get used. Even if the cli isn't pointing to it. 😄
Going to see though real quick if the gunicorn + debug produces anything
just set the workers to a fixed number
No yea, for sure. Was just circling back on that earlier topic
Yep, didn't change anything
show me the depoloy logs for your django app please
Still get this when I go directly to a backend url
can you send the link to the proxy
Bleacher Breaks Inventory
Inventory Management for Bleacker Breaks.
Oh lol, I have a typo in the desc :p
looks like it does make it to the django backend
You can see the pure frontend working if you go to https://website-reverse-proxy-production.up.railway.app/sign-in
Works for me. 500s becuase can't hit the auth endpoint becuase backend isn't working.
can you add
--forwarded-allow-ips="*"
to your gunicorn start commandWell the "good" news is that the requests are now responding with 301 and not 502. But not actually sure if that is better.
It is redirecting to nothing? Not sure.
Same result
django and or gunicorn is attempting to redirect for some reason, do you have any idea why?
The only thing I could think of is that I force things to be HTTPS:
This would normally work no issue. At least it has with Caddy. But maybe becuase these Caddyfiles have https off, it is messing with things? Idk how railway is taking care of https?
yeah dont do that
railway does https on its own proxy for you, you should run your app in http with no notion of https
What part should I be getting rid of?
But also, there really should be a way to make this work without removing that stuff
well railway sets a
X-Forwarded-Proto
header, so you need to have your app accept that valueIt feels very wrong to remove those protections on the django level
your app on railway can only ever be accessed over https so theres no issues removing them
I mean sure. But it is more like "extra precaution".
i promise you its not needed, there is no way to access a railway hosted app over http
This is going to make for quite the blog post. Eventually. Long list of backlog things to get to before I touch this.
well you have two options
- railway sets a
X-Forwarded-Proto
header, have your app accept that value
- remove anything that tries to redirect to https:party_cat:
It is working
I officially can transfer everything to railway.
....
That is going to be a bit of a pain. But it being possible is the first step. Now I just need to also do all the other silly things like add monitoring and add db backup cron stuff. That will be fun
use the railway template for db backups!
Yea, I will. Thanks
no problem!