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 8553009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:33:01+00:00 2026-06-11T14:33:01+00:00

I have a static site. I would like the simplest approach to password protecting

  • 0

I have a static site.

I would like the simplest approach to password protecting a directory, with a basic admin UI for adding/removing users. I will have so few users that I don’t care about performance.

I don’t care if it’s PHP or Django or whatever, I just want a complete software package.

  • Apache basic auth isn’t good, because you can’t log out. Nor is there a UI for adding users.

  • I tried throwing everything behind Django auth and serving the files through Django. However, Chrome treats all my text/css headers as text/plain, so I don’t get any stylesheets showing.

  • I can’t use mod_xsendfile on my server because I can’t reconfigure Apache to add new modules. I think this approach is overkill anyway.

Is there a code package that implements authentication with basic admin for a static site?

  • 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-11T14:33:02+00:00Added an answer on June 11, 2026 at 2:33 pm

    I use nginx and this is usually my solution. Maybe something similar to this is available for Apache. Don’t know.

    In nginx, proxy can return a response with header X-Accel-Redirect with the location to where nginx is suppose to redirect. For example with the following nginx config:

    server {
       ...
       location / {
           proxy_pass: ...;
       }
       location /media/secure/ {
           internal;
           alias ...;
       }
    }
    

    if the proxy pass will return:

    X-Accel-Redirect: /media/secure/somefile;
    

    Then nginx will redirect the request from the proxy to the /media/secure/ location, hence serving the static file.

    So I usually authenticate a user in Django and then just return that header with the location to the file which then nginx serves. This is nice because then Django does not have to serve static file, users can’t just access that secure location (because of the internal directive) and also because if all mime types are configured in nginx, then all the files are served properly…

    Again, this is for nginx, not for Apache, but maybe something similar is out there for Apache.

    EDIT

    Here is a simple Django code snippet assuming you are using same settings as above for nginx. This view serves secure files if its path is provided in the GET:

    @login_required()
    def serve_secure_static(request, file_root=os.path.join(settings.MEDIA_ROOT, 'secure')):
        if not request.method == 'GET':
            return HttpResponseBadRequest('Only GET allowed')
    
        if not 'file' in request.GET:
            return HttpResponseBadRequest('File query must be provided')
    
        # make sire loggen user is allowed to see the file
        # maybe check some custom permission
    
        file_path = request.GET['file']
    
        # if in DEBUG, make Django serve static file
        # because nginx might not be configured
        if settings.DEBUG:
            abs_file_path = os.path.join(file_root, file_path)
            file_data = open(abs_file_path, 'rb').read()
            return HttpResponse(file_data, mimetype=mimetypes.guess_type(file_path))
    
        # else make nginx serve static file
        else:
            redirect_url = '/%s' % file_path
            response = HttpResponse()
            response['X-Accel-Redirect'] = redirect_url
            return response
    

    So then if you add this view to urlconfig:

    url(r'^serve_secure_static/$', 'server_secure_static')
    

    you can request secure files by:

    http://domain.com/serve_secure_static/?file=path/to/file/here/relative/to/media/secure.css
    

    which will serve the file from

    /media/secure/path/to/file/here/relative/to/media/secure.css
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have many static images under a directory in my site structure, and I'm
I have developed a site, which has some static pages. Like explore, home, feedback.
I would like to serve static plist files using mod_wsgi . In have configured
How would I go about this? I have a mostly static site, which is
I would like to allow users to post HTML to a site but need
We have to develop an Ecommerce site with 20+ pages of static content which
I've got ~100 static HTML pages and would like to add them to my
I have Elmah up and running in my ASP.NET MVC site and I would
When I am adding a static view like this: cfg = config.Configurator(...) cfg.add_static_view(name='static', path='MyPgk:static')
I have a mostly static web site with no server-side code and just a

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.