Django REST Swagger HTTPS requests

6.4k views Asked by At

How configure django-rest-swagger to get a HTTPS requests?

upd: SSL cert is present and ALL app working with it, but swagger make a http requests.

5

There are 5 answers

5
zaidfazil On BEST ANSWER

Add this setting in your settings.py,

SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

For more details, refer documentation..

Also, you may need to make sure your server is forwarding x_forwarded_proto and on nginx add this to your location within server config:

proxy_set_header  X-Forwarded-Protocol  $scheme;
0
Muhammad Farhan Mughal On

Put url='https://your_server_address/', in get_schema_view function in urls.

But swagger now only works on https, if you want to work on both http and https you can handle this through env variables.

0
jerego On

All the above solutions didn't work for me, so i did something HORRIBLE that worked:

Edited drf_yasg/openapi.py Line 260

From:

self.schemes = [url.scheme]

To:

self.schemes = ["https"]

Obviously you should not do this because the next time someone installs requirements this change will be lost. But it helped me to get the documentation working on my server.

1
Kostas Livieratos On

That's not an issue with your swagger. Just install an SSL cert on your django-serving app server.

0
matyas On

@zaidfazil's answer almost worked for me. I had to add

SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

to my django settings but then I had to add

proxy_set_header X-Forwarded-Proto https;

instead of:

proxy_set_header  X-Forwarded-Protocol  $scheme;

inside nginx's location block that serves the django app.