Django / WSGI blank page - django

I am trying to get Django to work together with Apache using WSGI. The problem is that it simply returns an empty page (200 OK or 203 not modified).
I can't find any error upon restarting or when accessing the page in either error.log or django-error.log. There is an entry in django-access.log though.
WSGIPythonPath /web/django/dtest/
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /web/django
ServerName django.markv.nl
<Directory />
Options FollowSymLinks Includes
AllowOverride All
</Directory>
WSGIScriptAlias /wsgi-scripts/ /web/django/dtest/dtest/wsgi.py
LogLevel info
ErrorLog ${APACHE_LOG_DIR}/django-error.log
CustomLog ${APACHE_LOG_DIR}/django-access.log common
</VirtualHost>
I tried using the manage.py runserver, in which case it works fine, so it's really an apache/wsgi problem.
I tried disabling mod_php5 with no result (except that PHP stopped working).
Any clues what the problem is or where I can find an error? It's probably something trivial but I fail to find it...

You're serving your application at /wsgi-scripts/, which seems an odd thing to do, so you'll need to go to that URL to see it.
Note that you absolutely certainly do not want to set your DocumentRoot to the location of your Django files, although this is not the source of your problem.

Related

It's a bad idea to add localhost in the url of launching projects - Warning

I have a program called ‘project’ that I run from wamp, and everything goes correctly, the problem is that I'm getting the following warning every time I launch wamp:
It's a bad idea to add localhost in the url of launching projects. It is best to define VirtualHost in
wamp/bin/apache/apache2.4.37/conf/extra/httpd-vhosts.conf
file and not add localhost in the url.
I know there are similar questions with solutions, I have been reading several forums with solutions to solve the problem but I can not get the warning to disappear. In httpd-vhosts.conf I have the following:
# Virtual Hosts
#
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot "${INSTALL_DIR}/www"
<Directory "${INSTALL_DIR}/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
Can you help me solve it? I get the same warning even if I replace 'localhost' in serverName and ServerAlias with: C:/wamp64/www/project/
My wamp version is 3.1.7 - 64bit:
Within c:\wamp64\wampmanager.conf under [options] you should see urlAddLocalhost = "on", try switching its value to off and restart WAMP.
I'm sorry that I couldn't find any documentation that explains it. I know it because I was looking for something that could link my projects directly from http://localhost and tracked this option from the WAMP scripts. When I enabled it the warning started to show.
PS.: I'm afraid this method I described works only for WAMPSERVER >v3.1

How set different alias in django wsgi configuration?

In my configuration, I am using
WSGIScriptAlias /site1 /Library/WebServer/Documents/sampleapp/sampleapp/wsgi.py
instead of
WSGIScriptAlias / /Library/WebServer/Documents/sampleapp/sampleapp/wsgi.py
because my / has some other application hosted. Why this is not working? I am getting 404 page not found, but accroding to my understanding http://127.0.0.1/site1 should take me to django home page. Instead of I am getting this,
Full Configuration
<VirtualHost *:80>
WSGIDaemonProcess sampleapp python-path=/Library/WebServer/Documents/sampleapp:/Library/WebServer/Documents/sampleapp/env/lib/python2.7/site-packages
WSGIProcessGroup sampleapp
WSGIScriptAlias /site1 /Library/WebServer/Documents/sampleapp/sampleapp/wsgi.py
</VirtualHost>
This doesn't seem to have anything to do with your WSGI configuration. As you can see from the error message (which really you should have cut and pasted the text, rather than a screenshot), you have only defined URL patterns beginning with "djangoapp" and "admin". So you would need to go to "/site1/djangoapp" or "site1/admin/" to see your site. If that isn't what you want, then you'll need to change your urls.py.

403 forbidden when Django folder is located in /root

I'm trying to deploy my local Django site on my Ubuntu 12.04 server. I followed a tutorial, and everything seems to work fine, except Apache won't allow me to store my Django project under /root. More specifically, I get a 403 Forbidden when trying to access my site.
I suspect I need to configure my virtual host in a different manner. Any ideas?
Here is /etc/apache2/sites-available/mysite
<VirtualHost *:80>
ServerAdmin me#mysite.com
ServerName mysite.com
ServerAlias www.mysite.com
WSGIScriptAlias / /root/me/index.wsgi
Alias /static/ /root/me/static/
<Location "/static/">
Options -Indexes
</Location>
ErrorLog /var/log/mysite/error.log
</VirtualHost>
Thanks for the comments. I'll mark this as the correct answer for future reference.
I ended up moving the whole Django project to /home/anotheruser, and defined DocumentRoot as per Aamir Adnans suggestion. After service apache2 restart it started working.

Django urls.py catches all existing HTML projects' urls on WampServer

I had WampServer working perfectly with Aptana IDE using multiple folders for different html projects. Then I installed Django and added this to Apache's httpd.conf:
Alias /images/ "c:/wamp/www/daas/templates/images/"
<Directory "c:/wamp/www/daas/images>
Order allow,deny
Allow from all
</Directory>
WSGIScriptAlias / "c:/wamp/www/daas/apache/django.wsgi"
<Directory "c:/wamp/www/daas/apache">
Allow from all
</Directory>
<VirtualHost *:80>
ServerName 127.0.0.1
DocumentRoot c:/wamp/www/daas/
</VirtualHost>
and now the virtual hosts I had for html projects...
NameVirtualHost 127.0.0.1
<VirtualHost 127.0.0.1>
ServerName localhost
DocumentRoot 'C:\wamp\www'
</VirtualHost>
<VirtualHost 127.0.0.1>
ServerName projectA.local
DocumentRoot 'C:\wamp\www\projectA'
</VirtualHost>
don't load correctly because Django's urls.py is catching all urls The current URL, projectA, didn't match any of these regular expressions, even the ones not inside the Django's projects.
How can I solve this? On Djano's side or on Apache's side? Here (How do i run Django and phpmyadmin on apache webserver on ubuntu) is a similar problem but the solution didn't worked for me. And luckily localhost/phpmyadmin works correctly but localhost/projectA doesn't.
It looks like WSGIScriptAlias / "c:/wamp/www/daas/apache/django.wsgi" in your httpd.conf catches all requests on apache.

Running django site and wikis on the same linux machine with apache

I've got a bit of a problem with forcing django based site and a "regular" sites i.e. wikis to work on the same machine, and to top it I'm kinda new to this stuff...
I've been trying to setup this using the VirtualHost but it seems that this does not work very well. In other words I can either run the django site (alredy in form of host.com/djangosite) and other sites in the same time (i.e host.com/othersite1). Only one works at a time it looks like the apache runs first VirtualHost it finds.
the structure in the server looks like this
/var/www/djangosite
/var/www/othersite1
/var/www/othersite2 ... etc
Now the sites-enabled, I experimented a bit and finally ended up in one file with two VirtualHosts for now:
<VirtualHost *:80>
ServerAdmin ss#dd.gg
DocumentRoot /var/www/djangosite
ServerName host.com/djangosite
Alias /m/ "/var/www/djangosite/forum/skins/"
<Directory "/var/www/djangosite/forum/skins">
Order allow,deny
Allow from all
</Directory>
Alias /upfiles/ "/var/www/djangosite/forum/upfiles/"
<Directory "/var/www/djangosite/forum/upfiles">
Order deny,allow
Allow from all
</Directory>
WSGIScriptAlias /djangosite /var/www/djangosite/djangosite.wsgi
CustomLog /var/log/djangosite.access.log common
ErrorLog /var/log/djangosite.error.log
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/othersite1
ServerName host.com/othersite1
</VirtualHost>
On their own both VirtualHosts do ok, i.e. when I put this in a file in sites-enabled the djangosite works fine, the second is not found, (something with document root being rooted at wrong dir in filesystem structure). If I put the second Vhost on top it works the djangosite doesn't.
Ok. so now a real question is there a recipe for running djangosite and "regular" site on one linux/apache configuration with one NIC and one hostname.
thanks for at least reading :)
You don't need two seperate VirtualHosts. Just put them both in the same one, with the ServerName as just "host.com". Then you can use aliases - the WSGIScriptAlias for the Django site, and a normal Alias for the wiki.
One note: please do not put your Django code in the DocumentRoot. This is dangerous - it makes it potentially possible for people to see your code, including your passwords etc in settings.py. Move it somewhere else, and leave out the DocumentRoot directive.