5

I don't know what's wrong in my virtualhost for django project but the simply question is no matter what modification I do over this file stills output the same in error log from apache and not load any css or js files, what I can see is that Apache is looking for static and media file in the root web folder: /var/www

[Fri May 30 00:58:08 2014] [error] [client 192.168.1.145] File does not exist: /var/www/static, referer: http://192.168.1.143/dgp/login/

I set up virtual host file as follows:

  WSGIPythonPath /var/www/dgp_python2_7/bin/python2.7:/var/www/dgp_python2_7/lib/python2.7/site-packages
  WSGIScriptAlias /dgp /var/www/dgp/dgp/dgp/wsgi.py

  <VirtualHost 127.0.0.1:80>
      ServerName www.dgp.dev
      ServerAlias dgp.dev


     AliasMatch ^/([^/]*\.css) /var/www/dgp/dgp/static/$1

     Alias /media/ /var/www/dgp/dgp/media/
     Alias /static/ /var/www/dgp/dgp/static/
     Alias /images/ /var/www/dgp/dgp/images/

    <Directory /var/www/dgp/dgp/static/>
      Order deny,allow
      Allow from all
    </Directory>

    <Directory /var/www/dgp/dgp/media/>
      Order deny,allow
      Allow from all
    </Directory>

     ErrorLog /var/www/dgp/dgp/error.log
     CustomLog /var/www/dgp/dgp/access.log combined
  </VirtualHost>

And in settings.py STATIC_ROOT with '/var/www/dgp/dgp/static/' where is located all the css content.

How can I tell apache or Django to looking for the proper directory '/var/www/dgp/dgp/static/'? It's driving me crazy, I don't understand how something so elemental in development it's so complex for production.

Regards!

Edit with the solution

The really problem was that I didn't disable the default site for Debian Apache (that is the version I'm working for) and has another method for stablish virtualhost, at beginning we have to disable default site with the follow command: a2dissite defaultand everything works now like a charm!

Enot
  • 790
  • 2
  • 15
  • 34
  • 1
    Your VirtualHost definition likely isn't being used at all. In general it is a bad idea to use an IP address in VirtualHost because it is too easy to stuff things up. Using 127.0.0.1 especially would be a bad use. Try '*' instead of '127.0.0.1'. Also put your WSGIScriptAlias inside of the VirtualHost as well. – Graham Dumpleton May 30 '14 at 00:18
  • I tried before, it was as * and change to 127.0.0.1 only for test and nothing changes, WSGIScriptAlias never works when put it inside VirtualHost, only when is outside, I don't know what's wrong with that and if this could be the problem or not. – Enot May 30 '14 at 08:38
  • Sounds like you might have multiple conflicting VirtualHost definitions. What other VirtualHost definitions do you have setup? – Graham Dumpleton May 31 '14 at 06:32
  • I think you should answer your own question and mark it as the answer instead of placing the answer in the question. – Bobort Mar 02 '17 at 15:49

1 Answers1

1

You can tell where your static files are being looked for in your project's rendered html. Just view the source in your browser and look for a stylesheet or javascript include, what is the full path to the file?

My guess, you have to run Django's collect static script, which will collect all the static scripts in all of your project's app and put them into one location. This is a core part of deploying Django projects and unavoidable if you use multiple "apps" in your project.

in your terminal go to the Django projects root folder and type this:

python manage.py collectstatic

Read more at https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/

macguru2000
  • 2,042
  • 2
  • 18
  • 27
  • 2
    All the css content and js files are placed in one folder, static folder in this case, I ran that command before so I don't need to collect again in one folder, the directives are fine, the routes are fine but for some reason I can't grasp Apache stills looking fot static files in web root folder. – Enot May 30 '14 at 09:58