0

I use an apache container which acts as a loadbalancer and redirects the flow to 2 apache wsgi. I use django-rest-framework on the 2 apaches.

I have a problem to get the files. Indeed, the api returns me:

{
    avatar: http://127.0.0.1:8000/media/avatars/2.jpg
}

Instead of http://127.0.0.1:8000/, I want the api to return https://api.myservice/

How to force the url ?

darkvodka
  • 303
  • 1
  • 3
  • 11

1 Answers1

1

Looks similar to this question. The answer there mentions:

Django's reverse uses request's domain to build absolute URL.

So make sure to pass the Host header in your proxy. From the comments on the linked answer, ProxyPreserveHost should do the job for Apache.

  • Thank you for your answer. it works well with ProxyPreserveHost – darkvodka Oct 26 '21 at 08:34
  • I still have a problem. It works for everything except the images. Django rest framework return image in http and not https. The apache on the other hand returns everything in http in https. When I open a page, I have the redirection from http to https for the image (thanks to apache) but firefox tells me that the connection is not secure. – darkvodka Oct 27 '21 at 13:12
  • @darkvodka take a look here https://stackoverflow.com/questions/59071562/django-media-url-return-https-instead-of-http – Sasja Vandendriessche Oct 28 '21 at 11:07