Opened 6 years ago

Closed 6 years ago

#18591 closed Cleanup/optimization (worksforme)

Missing crucial info in Apache conf (httpd.conf) to serve static files

Reported by: rschuon@… Owned by: nobody
Component: Documentation Version: 1.4
Severity: Normal Keywords: Apache, mod-wsgi, uWSGI, Static, Media
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Your page:

To get Apache to be able to serve files statically, the handler (mod-wsgi, or uWSGI) must be disabled for those folders. So, you need another directive under the ones you list, that looks like this:

<Location /static>
        SetHandler default-handler

I believe the /static location directive must occur after the / Location directive to turn the handler off correctly.
This allows the request to be caught by Apache rather than uWSGI, and redirected to the static file folder.

Also, the line:

Alias /static/ /usr/local/wsgi/static/

Should actually look like this:

Alias /static /usr/local/wsgi/static/

Without the trailing slash on the alias.

Change History (5)

comment:1 in reply to:  description Changed 6 years ago by Melvyn Sopacua

Replying to rschuon@…:

Also, the line:

Alias /static/ /usr/local/wsgi/static/

Should actually look like this:

Alias /static /usr/local/wsgi/static/

Without the trailing slash on the alias.

That's incorrect. It should have the slash. Read up on mod_speling if you want a directory listing without having to type an extra slash, but the correct way is to map the trailing slash to the directory.

comment:2 Changed 6 years ago by Luke Plant

Triage Stage: UnreviewedAccepted

comment:3 Changed 6 years ago by Luke Plant

For 1.4/master the page to change is now this one:

comment:4 Changed 6 years ago by Tim Graham

I'm not an expert in Apache configuration, but I'm not sure this ticket is valid, or at least there's some clarification that needs to be added. I have Django mod_wsgi sites that serve static files just fine using what's currently in the docs. In fact, the suggestion seems to contradict the mod_wsgi docs:

Note that there is never a need to use SetHandler to reset the Apache content handler back to 'None' for URLs mapped to static files. That this is a requirement for mod_python is a short coming in mod_python, do not do the same thing for mod_wsgi.

comment:5 Changed 6 years ago by Claude Paroz

Resolution: worksforme
Status: newclosed

Quotation added by Timo explains why the Location directive seems not necessary.

About the Alias issue, here is what Apache2 docs have to say:

    Note that if you include a trailing / on the URL-path then the server will require a 
    trailing / in order to expand the alias. That is, if you use

    Alias /icons/ /usr/local/apache/icons/

    then the url /icons will not be aliased, as it lacks that trailing /. Likewise, if
    you omit the slash on the URL-path then you must also omit it from the file-path.

So both are possible and produce slightly different behaviour when the request is exactly "/static", which appears to be a corner case anyway (and if APPEND_SLASH is True, that will probably redirect to "/static/"). I think that the slash-ending version will suit most configurations very well and I suggest to not change it.

Note: See TracTickets for help on using tickets.
Back to Top