Monday, September 2, 2019

Apache Django - Site is https but api, media, static and internal urls in http

You have configured your django application in Apache as https but when you open the web page in browser, still it shows internal urls like media static and API urls in http. You are using internal urls as absolute urls and you have configured https in all required places in settings.py but still no luck. Here is solution for you.

Solution :
You need to make sure apache forwards the client's request scheme as https for Django. You need to add the following line in your virtualhost.
RequestHeader set "X-Forwarded-Proto" expr=%{REQUEST_SCHEME}
RequestHeader set "X-Forwarded-SSL" expr=%{HTTPS}

Restart Apache.

If you are using nginx and you are facing same issue, you need to add similar line in your virtualhost in nginx configuration file.

proxy_set_header X-Forwarded-Proto $scheme;
Restart Nginx.
Now load the web page. All internal urls should be opened as https.

No comments:

Post a Comment