#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.

Attachments (0)

Change History (5)

comment:1 in reply to: ↑ description Changed 22 months ago by msopacua

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 22 months ago by lukeplant

  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 22 months ago by lukeplant

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

comment:4 Changed 18 months ago by timo

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 18 months ago by claudep

  • Resolution set to worksforme
  • Status changed from new to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.