views:

825

answers:

2

This question has been retitled/retagged so that others may more easily find the solution to this problem.


I am in the process of trying to migrate a project from the Django development server to a Apache/mod-wsgi environment. If you had asked me yesterday I would have said the transition was going very smoothly. My site is up, accessible, fast, etc. However, a portion of the site relies on file uploads and with this I am experiencing the strangest and most maddening issue. The particular page in question uses swfupload to POST a file and associated metadata to a url which catches the file and initiates some server-side processing. This works perfectly on the development server, but whenever I POST to this url on Apache the Django request object comes up empty--no GET, POST, or FILES data.

I have eliminated client-side issues by snooping with Wireshark. As far as I can discern the root cause stems from some sort of Apache configuration issue, possibly related to the temporary file directory I am trying to access. I am a relative newcomer to Apache configuration and have been banging my head against this for hours.

My Apache config:

<VirtualHost *:80>
ServerAdmin [email protected]
ServerName  sitename.com
ServerAlias www.sitename.com
LogLevel warn
WSGIDaemonProcess sitename processes=2 maximum-requests=500 threads=1
WSGIProcessGroup sitename
WSGIScriptAlias / /home/user/src/sitename/apache/django.wsgi
Alias /static /home/user/src/sitename/static
Alias /media /usr/share/python-support/python-django/django/contrib/admin/media
</VirtualHost>

My intuition is that this may have something to do with the permissions of the file upload directory I have specified in my Django settings.py ('/home/sk/src/sitename/uploads/'), however my Apache error log doesn't suggest anything of the sort, even with the log level bumped up to debug.

Suggestions on how I should go about debugging this?

+3  A: 

Normally apache runs as a user "www-data"; and you could have problems if it doesn't have read/write access. However, your setup doesn't seem to use apache to access the '/home/sk/src/sitename/uploads'; my understanding from this config file is unless it hit /static or /media, apache will hand it off WGSI, so it might be good to check out those permissions and logs, rather than the apache ones.

Todd Gardner
+1: It's always permissions. Always. In the rare case when it isn't permissions, it's always the PYTHONPATH. In the really rare case when it isn't the PYTHONPATH it's a misspelled filename somewhere else.
S.Lott
Both these comments follow my intuitions. I will do some more investigation into the WSGI permissions tonight. I did try several variations, including setting the daemon to run as my login user (who certainly ought to have access), but the results were the same.
bouvard
Hmmm, according to the wsgi documentation (http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines), the user and group parameters of the WSGIDaemonProcess command are ignored if Apache is not started as root. That could be the problem. If that is the case then I need to explicitly grant www-data access to '/home/sk/src/sitename/uploads'. Its no wonder I'm a programmer and not a sysadmin... damn permissions drive me nuts.
bouvard
Well, I ran the brute force test and recursively chmod'ed the project directory to be writable by any user and still no dice. I get the exact same issue. Empty GET, POST, and FILES with no errors in the logs. Everything with the PYTHONPATH looks correct. Going to try Mapio's solution next, but I'm open to other suggestions.
bouvard
+2  A: 

Another possibility is a bug in "old" releases of mod_wsgi (I got crazy to find, and fix, it). More info in this bug report. I fixed it (for curl uploads) thanks to the following hint (that works on the CLI too, using the -H switch).

Mapio
This does sound exactly like the issue I am having, and IN FACT the version of modwsgi shipping with Ubuntu Jaunty does not include this fix. Although I am not using Opera its certainly possible that Flash exhibits similar behavior. You may be the winner Mapio, in which case I will most certainly owe you a beer for pointing this out. I will test tonight. :-)
bouvard
You sir, have my undying admiration. If you are ever in California, drop by. I owe you more than one.
bouvard
I live in Italy, but in case I'll be so lucky to have a vacation in California, I'll be happy to share one with you!
Mapio