Nginx SSL on Django admin site

November 2, 2014 3k views


Droplet: Ubuntu Django on 14.04

I want to configure Nginx to serve the admin portion of my Django site over SSL but not the rest of the site. The admin features are at*. Is there a way to just serve this location over SSL?


1 Answer

Yes, basically what you do is make it redirect the URL when you’re accessing /admin, something like this:

location /admin {
    return 301 https://$server_name$request_uri;

Then you have a server-block which will handle all the SSL-requests, basically the same as your other server-block for non-SSL traffic, but only listening on SSL. If you choose to combine the two server-blocks into one you have to check every request with an if-statement, which is not recommended.

Have another answer? Share your knowledge.