I've set up a Django application on a Linux server (Ubuntu server 12.4), using Apache (mod_wsgi) and PostgreSQL (psycopg2). I had problems with Postgres' unix authentication, so I chose a regular user as both the database owner and the apache user. It worked fine, but now I have to be logged in with that user for mod_wsgi to work. If I'm not logged in, apache serves static files normally, but when trying to access mod_wsgi the following error occurs:

[...] [error] [...] Target WSGI script not found or unable to stat: /parent/folder

I tried checking the permissions for the file (including setting it to 777) but still getting the same error (the parent folders are also readable from everyone). The file (along with static files and Django files) are stored in the same user's home directory. I'm stuck now, any ideas?

P.S. I'm very inexperienced with *nix machines, I've set this up as a hack to get the system up and running. But I'd rather have a different user for Apache and PostgreSQL, or at least the same user for both but not a regular one (i.e. one that will be also used to log in and do stuff). A quick solution I can use right away would be awesome, but a proper one - even if I can't apply immediatly - would also be very welcome.

Update: my apache2.conf file is mostly unmodified (from the default settings), only changed the user and group:

User myuser
Group myuser

(the user and group names are the same)

The file with the virtual hosts contains pretty much a standard Django install, but with every file stored in that user's home folder (set to 755, confirmed accessible by Apache):

<VirtualHost *:80>

    DocumentRoot /home/myuser/myproject
    <Directory />
        Options All
        AllowOverride None
    <Directory /home/myuser/myproject>
        Options All
        AllowOverride None
        Order allow,deny
        allow from all

    WSGIDaemonProcess myproject processes=6 threads=1
    WSGIProcessGroup myproject

    Alias /media/ "/home/myuser/myproject/media/"
    Alias /static/ "/home/myuser/myproject/static/"
    WSGIScriptAlias / "/home/myuser/myproject/myproject.wsgi"

    ErrorLog /var/log/apache2/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog /var/log/apache2/access.log combined

I've already left my customer's site, but I'll try to replicate the setup at my development machine ASAP (so I'm mostly interested in a proper solution rather than a quick fix). Any hints or pointers are welcome.

  • Can you post your Apache config? – Banjer Jun 22 '12 at 19:33
  • @Banjer posted. There's nothing unusual in it as far as I can tell, and I've used a similar setup in windows machines with no issues. I've already solved most permission denied problems (all relevant files are 755), and this error only occurs when I'm not currently logged in with myuser. – mgibsonbr Jun 22 '12 at 21:40

The home directory of myuser was encrypted, which means it was only mounted when the user was logged in. So, even with the right permissions, the Apache process couldn't read the wsgi file, resulting in the "not found" log entry. The static files were cached, for that reason they were still being loaded fine (for some time).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.