Django REST Swagger HTTPS requests
Asked Answered
R

5

7

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.

Ramey answered 28/7, 2017 at 11:31 Comment(0)
L
20

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;
Langdon answered 31/7, 2017 at 6:53 Comment(5)
its not help for meRamey
Did you add the settings in your nginx config file?Langdon
sure, i add settings in my nginx conf.Ramey
Could you show the relevant piece of code you've added?Langdon
Any apache specific settings? I have a "redirect permanent / localhost.my.org"Carlita
D
2

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.

Droplight answered 25/9, 2020 at 12:19 Comment(0)
D
0

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.

Deuteranopia answered 1/6, 2022 at 5:34 Comment(0)
A
-1

@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.

Alisonalissa answered 12/6, 2019 at 15:29 Comment(0)
D
-5

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

Domineca answered 28/7, 2017 at 15:21 Comment(1)
SSL cert is present and ALL app working with it, but swagger make a http requests.Ramey

© 2022 - 2024 — McMap. All rights reserved.