Nginx SSL on Django admin site

Posted November 2, 2014 4.5k 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?


These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
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.