Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8884561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:05:23+00:00 2026-06-14T21:05:23+00:00

My django app (let me call it partlysecureapp )has an index page which is

  • 0

My django app (let me call it partlysecureapp)has an index page which is visible to all.All the other pages (reachable from links on index page) need the user to log in. I want to use the app with SSL in apache2.

I already have an app(say mysecureapp) deployed on apache with SSL, which has all pages needing login by the user. I have set the configurations for this as follows.

My apache2 is at /etc/apache2 which has the following directory structure.

/etc/apache2/
            |--conf.d---*charset,security,localized-error-pages* 
            |---mods-available---...
            |---mods-enabled---...
            |---sites-available---default,default-ssl,ssl
            |---sites-enabled---shortcut to ssl
            |---apach2.conf
            |---httpd.conf
            |---ports.conf
            |---magic
            |---envvars

For the secureapp, I have set this in file sites-available/ssl

<VirtualHost *:443>
    ServerAdmin webmaster@localhost

    DocumentRoot /home/dev/python/django/mysecureapp

        SSLEngine on
        SSLOptions +StrictRequire
        SSLCertificateFile /etc/ssl/certs/server.crt
        SSLCertificateKeyFile /etc/ssl/private/server.key
    ...
    WSGIScriptAlias /mysecureapp /home/dev/python/django/mysecureapp/mysecureapp.wsgi
    Alias /site_media/ /home/dev/python/django/mysecureapp/media/

</VirtualHost>

This works perfectly..

To deploy my partlysecureapp,

http://127.0.0.1:8080/partlysecureapp/ need to show index page which is accessible to all.
but

../partlysecureapp/link1/
../partlysecureapp/link2/
../partlysecureapp/link3/

require login and should be served through ssl .

I think, I need to add another WSGIScriptAlias for my partlysecureapp. Do I need to add another DocumentRoot for the partlysecureapp? How to tell apache to serve the index page from port 8080 and others through ssl port?

As of now the /etc/apache2/httpd.conf is blank. Only the sites-available/ssl file has a VirtualHost element.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T21:05:24+00:00Added an answer on June 14, 2026 at 9:05 pm

    First of all, let’s separate the concerns here: one thing is to require login, other is to require SSL. The former is specific to Django, and should be handled in your views; and for the latter, IMHO you should consider the possibiilty of serving everything through SSL, that would simplify your setup a lot. Sure, there’s some overhead, and it’s up to you to decide whether it matters or not for your particular case.

    That said, for your proposed scenario:

    1. To serve anything from plain HTTP, you need to listen to the port 80 (or, in your case, 8080). So you need a separate VirtualHost bound to that port, with a separate WSGI application for itself.

    2. To allow a single path (your index file) from this virtual host, but require everything else to be served by the SSL protected one, you can use mod_rewrite:

      RewriteEngine On
      RewriteRule ^/partlysecureapp$ - [L,NC]
      RewriteRule (.*) https://127.0.0.1/partlysecureapp%{REQUEST_URI} [L,R=301]
      

      The first rule tells Apache not to perform any redirect if the path is exactly like your root path; the second redirects everything else to https (which will be handled by your *:443 virtual host).

      (Note: you might want to serve /site_media without SSL as well)

    3. Then you can simply add your WSGI alias; even if Django sends the user to a different page, Apache will ensure that page is served through SSL.

    You final code would be something like:

    <VirtualHost *:8080>
        ServerAdmin webmaster@localhost
    
        DocumentRoot /home/dev/python/django/partlysecureapp
    
        RewriteEngine On
        RewriteRule ^/partlysecureapp$ - [L,NC]
        RewriteRule ^/site_media - [L,NC]
        RewriteRule (.*) https://127.0.0.1/partlysecureapp%{REQUEST_URI} [L,R=301]
    
        ...
        WSGIScriptAlias /partlysecureapp /home/dev/python/django/partlysecureapp/partlysecureapp.wsgi
        Alias /site_media/ /home/dev/python/django/partlysecureapp/media/
    </VirtualHost>
    

    And your code for the SSL protected virtual host would be identical to the mysecureapp one (using partlysecureapp instead, of course; note also that you can have both apps running side-by-side, just pay attention to your MEDIA and STATIC paths).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my django app, I have a view which accomplishes file upload.The core snippet
I have a Django app that gets it's data completely from an external source
Let's suppose I have the following url: /valid/django/app/path/?foo=bar&spam=eggs I can simulate a request to
A Django app that I am working has an Event model. An Event may
I want to let users interact with my Django app via SMS. Twilio's pricing
I want to open a file from a Django app using open() . The
In my Django web page I need Javascript to call a public method of
I know Django has a feature of last_modified field (models.DateTimeField(auto_now_add=True) ).. but let's say
I'm trying to develop a web app with Django that would let users to
Other posters have previously said in this forum that when your Django app starts

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.